Compare commits

...

3 Commits

Author SHA1 Message Date
Sergey Shelomentsev
1c42fadb25 JBR-5441 fix wait for idle 2023-03-30 21:31:45 +03:00
Sergey Shelomentsev
26d93b189e JBR-5440 fix calculations for double click location 2023-03-30 15:48:53 +03:00
Maxim Kartashev
4445998aeb JBR-5431 Include memory used by JNI references into crash reports 2023-03-30 08:48:54 +04:00
8 changed files with 167 additions and 2 deletions

View File

@@ -262,6 +262,23 @@ void JNIHandles::print_on(outputStream* st) {
st->flush();
}
// Called while generating crash log, possibly not at safepoint
void JNIHandles::print_on_unsafe(outputStream* st) {
st->print_cr("JNI global refs: " SIZE_FORMAT ", weak refs: " SIZE_FORMAT,
global_handles()->allocation_count(),
weak_global_handles()->allocation_count());
st->cr();
st->flush();
}
void JNIHandles::print_memory_usage_on(outputStream *st) {
st->print_cr("JNI global refs memory usage: " SIZE_FORMAT ", weak refs: " SIZE_FORMAT,
global_handles()->total_memory_usage(),
weak_global_handles()->total_memory_usage());
st->cr();
st->flush();
}
void JNIHandles::print() { print_on(tty); }
class VerifyJNIHandles: public OopClosure {

View File

@@ -110,6 +110,8 @@ public:
// Debugging
static void print_on(outputStream* st);
static void print_on_unsafe(outputStream* st);
static void print_memory_usage_on(outputStream* st);
static void print();
static void verify();
// The category predicates all require handle != nullptr.

View File

@@ -204,6 +204,7 @@ void VM_PrintThreads::doit() {
Threads::print_on(_out, true, false, _print_concurrent_locks, _print_extended_info);
if (_print_jni_handle_info) {
JNIHandles::print_on(_out);
JNIHandles::print_memory_usage_on(_out);
}
}

View File

@@ -43,6 +43,7 @@
#include "runtime/flags/jvmFlag.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/javaThread.inline.hpp"
#include "runtime/jniHandles.hpp"
#include "runtime/init.hpp"
#include "runtime/os.inline.hpp"
#include "runtime/osThread.hpp"
@@ -1076,6 +1077,11 @@ void VMError::report(outputStream* st, bool _verbose) {
STEP_IF("Native Memory Tracking", _verbose)
MemTracker::error_report(st);
STEP("JNI global references")
st->print_cr("JNI global refs:");
JNIHandles::print_on_unsafe(st);
JNIHandles::print_memory_usage_on(st);
STEP_IF("printing system", _verbose)
st->cr();
st->print_cr("--------------- S Y S T E M ---------------");

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2023 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @test
* @summary Verifies that the HotSpot crash log includes information
* about the number of JNI references and their associated
* memory consumption.
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @run main JNIRefsInCrashLog
*/
import jdk.internal.misc.Unsafe;
import jdk.test.lib.Asserts;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import java.util.ArrayList;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.nio.file.Files;
public class JNIRefsInCrashLog {
static final String HS_ERR_FILE_NAME = "hs_err_42.txt";
static final Unsafe unsafe = Unsafe.getUnsafe();
public static void main(String args[]) throws Exception {
if (args.length > 0 && args[0].equals("--test")) {
unsafe.putAddress(0, 42);
} else {
generateAndVerifyCrashLogContents();
}
}
public static void generateAndVerifyCrashLogContents() throws Exception {
ArrayList<String> opts = new ArrayList<>();
opts.add("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED");
opts.add("-XX:-CreateCoredumpOnCrash");
opts.add("-XX:ErrorFile=./" + HS_ERR_FILE_NAME);
opts.add(JNIRefsInCrashLog.class.getName());
opts.add("--test");
ProcessBuilder pb = ProcessTools.createTestJvm(opts);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain(HS_ERR_FILE_NAME);
final Path hsErrPath = Paths.get(HS_ERR_FILE_NAME);
if (!Files.exists(hsErrPath)) {
throw new RuntimeException(HS_ERR_FILE_NAME + " file missing");
}
final String hsErrorFile = new String(Files.readAllBytes(hsErrPath));
System.out.println(hsErrorFile);
if (!hsErrorFile.contains("JNI global refs memory usage:")) {
throw new RuntimeException("JNI global refs memory usage missing from " + HS_ERR_FILE_NAME);
}
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @summary Verifies that jstack includes information on memory
* consumed by JNI global/weak references
* @library /test/lib
* @run main/othervm JNIRefsInJstack
*/
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.Platform;
import java.io.IOException;
public class JNIRefsInJstack {
public static void main(String[] args) {
long pid = ProcessHandle.current().pid();
final OutputAnalyzer jstackOutput = runJstack(pid);
jstackOutput.shouldHaveExitValue(0)
.shouldContain("JNI global refs memory usage:");
}
static OutputAnalyzer runJstack(long pid) {
try {
final String JSTACK = JDKToolFinder.getTestJDKTool("jstack");
final ProcessBuilder pb = new ProcessBuilder(JSTACK, String.valueOf(pid));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.outputTo(System.out);
output.shouldHaveExitValue(0);
return output;
} catch (IOException e) {
throw new RuntimeException("Launching jstack failed", e);
}
}
}

View File

@@ -155,8 +155,8 @@ public class HitTestNonClientArea {
robot.delay(300);
robot.mouseMove(initialX, initialY);
}
robot.waitForIdle();
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
Point newLocation = window.getLocationOnScreen();
passed = initialLocation.x < newLocation.x && initialLocation.y < newLocation.y;

View File

@@ -132,7 +132,7 @@ public class MaximizeWindowTest {
private static void doubleClickToTitleBar(Window window, WindowDecorations.CustomTitleBar titleBar) throws AWTException {
int leftX = window.getInsets().left + (int) titleBar.getLeftInset();
int rightX = window.getBounds().width - window.getInsets().right - (int) titleBar.getRightInset();
int x = window.getLocationOnScreen().x + (rightX - leftX) / 2;
int x = window.getLocationOnScreen().x + leftX + (rightX - leftX) / 2;
int topY = window.getInsets().top;
int bottomY = (int) TestUtils.TITLE_BAR_HEIGHT;
int y = window.getLocationOnScreen().y + (bottomY - topY) / 2;