Skip to content
Permalink
Browse files
8253794: TestAbortVMOnSafepointTimeout never timeouts
Reviewed-by: pchilanomate, dcubed, mdoerr
  • Loading branch information
robehn committed Oct 5, 2020
1 parent f2f77f7 commit c9d0407e9477b7fb8fcb46d299505447ef7231fe
Showing with 31 additions and 45 deletions.
  1. +5 −0 src/hotspot/share/prims/whitebox.cpp
  2. +24 −45 test/hotspot/jtreg/runtime/Safepoint/TestAbortVMOnSafepointTimeout.java
  3. +2 −0 test/lib/sun/hotspot/WhiteBox.java
@@ -2289,6 +2289,10 @@ WB_ENTRY(jboolean, WB_IsJVMTIIncluded(JNIEnv* env, jobject wb))
return INCLUDE_JVMTI ? JNI_TRUE : JNI_FALSE;
WB_END

WB_ENTRY(void, WB_WaitUnsafe(JNIEnv* env, jobject wb, jint time))
os::naked_short_sleep(time);
WB_END

#define CC (char*)

static JNINativeMethod methods[] = {
@@ -2540,6 +2544,7 @@ static JNINativeMethod methods[] = {
{CC"aotLibrariesCount", CC"()I", (void*)&WB_AotLibrariesCount },
{CC"getKlassMetadataSize", CC"(Ljava/lang/Class;)I",(void*)&WB_GetKlassMetadataSize},
{CC"isJVMTIIncluded", CC"()Z", (void*)&WB_IsJVMTIIncluded},
{CC"waitUnsafe", CC"(I)V", (void*)&WB_WaitUnsafe},
};


@@ -1,4 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -23,79 +24,57 @@

import jdk.test.lib.*;
import jdk.test.lib.process.*;
import sun.hotspot.WhiteBox;

/*
* @test TestAbortVMOnSafepointTimeout
* @summary Check if VM can kill thread which doesn't reach safepoint.
* @bug 8219584 8227528
* @requires vm.compiler2.enabled
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run driver TestAbortVMOnSafepointTimeout
* @library /testlibrary /test/lib
* @build TestAbortVMOnSafepointTimeout
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestAbortVMOnSafepointTimeout
*/

public class TestAbortVMOnSafepointTimeout {

public static void main(String[] args) throws Exception {
if (args.length > 0) {
int result = test_loop(3);
System.out.println("This message would occur after some time with result " + result);
return;
}

testWith(500, 500);
}

static int test_loop(int x) {
int sum = 0;
if (x != 0) {
// Long running loop without safepoint.
for (int y = 1; y < Integer.MAX_VALUE; ++y) {
if (y % x == 0) ++sum;
}
}
return sum;
}

public static void testWith(int sfpt_interval, int timeout_delay) throws Exception {
// -XX:-UseCountedLoopSafepoints - is used to prevent the loop
// in test_loop() to poll for safepoints.
// -XX:LoopStripMiningIter=0 and -XX:LoopUnrollLimit=0 - are
// used to prevent optimizations over the loop in test_loop()
// since we actually want it to provoke a safepoint timeout.
// -XX:-UseBiasedLocking - is used to prevent biased locking
// handshakes from changing the timing of this test.
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xbootclasspath/a:.",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:-UseBiasedLocking",
"-XX:+WhiteBoxAPI",
"-XX:+SafepointTimeout",
"-XX:+SafepointALot",
"-XX:+AbortVMOnSafepointTimeout",
"-XX:SafepointTimeoutDelay=" + timeout_delay,
"-XX:GuaranteedSafepointInterval=" + sfpt_interval,
"-XX:-TieredCompilation",
"-XX:-UseCountedLoopSafepoints",
"-XX:LoopStripMiningIter=0",
"-XX:LoopUnrollLimit=0",
"-XX:CompileCommand=compileonly,TestAbortVMOnSafepointTimeout::test_loop",
"-Xcomp",
"-XX:SafepointTimeoutDelay=50",
"-XX:GuaranteedSafepointInterval=1",
"-XX:-CreateCoredumpOnCrash",
"-Xms64m",
"TestAbortVMOnSafepointTimeout",
"runTestLoop"
"TestAbortVMOnSafepointTimeout$Test",
"999" /* 999 is max unsafe sleep */
);

OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldMatch("Timed out while spinning to reach a safepoint.");
if (Platform.isWindows()) {
output.shouldMatch("Safepoint sync time longer than");
} else {
output.shouldMatch("SIGILL");
if (Platform.isLinux()) {
output.shouldMatch("(sent by kill)");
}
output.shouldMatch("TestAbortVMOnSafepointTimeout.test_loop");
}
output.shouldNotHaveExitValue(0);
}

public static class Test {
public static void main(String[] args) throws Exception {
Integer waitTime = Integer.parseInt(args[0]);
WhiteBox wb = WhiteBox.getWhiteBox();
// Loop here to cause a safepoint timeout.
while (true) {
wb.waitUnsafe(waitTime);
}
}
}
}
@@ -617,4 +617,6 @@ public native int validateCgroup(String procCgroups,
public native void checkThreadObjOfTerminatingThread(Thread target);

public native boolean isJVMTIIncluded();

public native void waitUnsafe(int time_ms);
}

1 comment on commit c9d0407

@bridgekeeper

This comment has been minimized.

Copy link

@bridgekeeper bridgekeeper bot commented on c9d0407 Oct 5, 2020

Please sign in to comment.