8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others

Reviewed-by: kvn, thartmann, iignatyev
This commit is contained in:
Igor Ignatyev 2014-11-21 17:27:11 +03:00
parent 5ef6d4e99d
commit bf5546e48d
6 changed files with 131 additions and 1 deletions

View file

@ -415,6 +415,7 @@ class CompileBroker: AllStatic {
shutdown_compilaton = 2 shutdown_compilaton = 2
}; };
static jint get_compilation_activity_mode() { return _should_compile_new_jobs; }
static bool should_compile_new_jobs() { return UseCompiler && (_should_compile_new_jobs == run_compilation); } static bool should_compile_new_jobs() { return UseCompiler && (_should_compile_new_jobs == run_compilation); }
static bool set_should_compile_new_jobs(jint new_state) { static bool set_should_compile_new_jobs(jint new_state) {
// Return success if the current caller set it // Return success if the current caller set it

View file

@ -944,6 +944,16 @@ WB_ENTRY(jobjectArray, WB_GetCodeHeapEntries(JNIEnv* env, jobject o, jint blob_t
return result; return result;
WB_END WB_END
WB_ENTRY(jint, WB_GetCompilationActivityMode(JNIEnv* env, jobject o))
return CompileBroker::get_compilation_activity_mode();
WB_END
WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr))
ThreadToNativeFromVM ttn(thread);
CodeBlobStub stub((CodeBlob*) addr);
return codeBlob2objectArray(thread, env, &stub);
WB_END
WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o)) WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o))
return (jlong) Thread::current()->stack_size(); return (jlong) Thread::current()->stack_size();
WB_END WB_END
@ -1194,6 +1204,9 @@ static JNINativeMethod methods[] = {
{CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob }, {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob },
{CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob }, {CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob },
{CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries }, {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries },
{CC"getCompilationActivityMode",
CC"()I", (void*)&WB_GetCompilationActivityMode},
{CC"getCodeBlob", CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob },
{CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize }, {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize },
{CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize }, {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize },
}; };

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* 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.
*
*/
import java.lang.management.MemoryPoolMXBean;
import java.util.EnumSet;
import java.util.ArrayList;
import sun.hotspot.WhiteBox;
import sun.hotspot.code.BlobType;
import sun.hotspot.code.CodeBlob;
import com.oracle.java.testlibrary.Asserts;
/*
* @test OverflowCodeCacheTest
* @bug 8059550
* @library /testlibrary /testlibrary/whitebox
* @build OverflowCodeCacheTest
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
* -XX:-SegmentedCodeCache OverflowCodeCacheTest
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
* -XX:+SegmentedCodeCache OverflowCodeCacheTest
* @summary testing of code cache segments overflow
*/
public class OverflowCodeCacheTest {
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
public static void main(String[] args) {
EnumSet<BlobType> blobTypes = BlobType.getAvailable();
for (BlobType type : blobTypes) {
new OverflowCodeCacheTest(type).test();
}
}
private final BlobType type;
private final MemoryPoolMXBean bean;
private OverflowCodeCacheTest(BlobType type) {
this.type = type;
this.bean = type.getMemoryPool();
}
private void test() {
System.out.printf("type %s%n", type);
System.out.println("allocating till possible...");
ArrayList<Long> blobs = new ArrayList<>();
try {
long addr;
int size = (int) (getHeapSize() >> 7);
while ((addr = WHITE_BOX.allocateCodeBlob(size, type.id)) != 0) {
blobs.add(addr);
BlobType actualType = CodeBlob.getCodeBlob(addr).code_blob_type;
if (actualType != type) {
// check we got allowed overflow handling
Asserts.assertTrue(type.allowTypeWhenOverflow(actualType),
type + " doesn't allow using " + actualType + " when overflow");
}
}
Asserts.assertNotEquals(WHITE_BOX.getCompilationActivityMode(), 1 /* run_compilation*/,
"Compilation must be disabled when CodeCache(CodeHeap) overflows");
} finally {
for (Long blob : blobs) {
WHITE_BOX.freeCodeBlob(blob);
}
}
}
private long getHeapSize() {
return bean.getUsage().getMax();
}
}

View file

@ -151,6 +151,8 @@ public class WhiteBox {
public native void freeCodeBlob(long addr); public native void freeCodeBlob(long addr);
public native void forceNMethodSweep(); public native void forceNMethodSweep();
public native Object[] getCodeHeapEntries(int type); public native Object[] getCodeHeapEntries(int type);
public native int getCompilationActivityMode();
public native Object[] getCodeBlob(long addr);
// Intered strings // Intered strings
public native boolean isInStringTable(String str); public native boolean isInStringTable(String str);

View file

@ -36,7 +36,13 @@ public enum BlobType {
// Execution level 2 and 3 (profiled) nmethods // Execution level 2 and 3 (profiled) nmethods
MethodProfiled(1, "CodeHeap 'profiled nmethods'"), MethodProfiled(1, "CodeHeap 'profiled nmethods'"),
// Non-nmethods like Buffers, Adapters and Runtime Stubs // Non-nmethods like Buffers, Adapters and Runtime Stubs
NonNMethod(2, "CodeHeap 'non-nmethods'"), NonNMethod(2, "CodeHeap 'non-nmethods'") {
@Override
public boolean allowTypeWhenOverflow(BlobType type) {
return super.allowTypeWhenOverflow(type)
|| type == BlobType.MethodNonProfiled;
}
},
// All types (No code cache segmentation) // All types (No code cache segmentation)
All(3, "CodeCache"); All(3, "CodeCache");
@ -57,6 +63,11 @@ public enum BlobType {
} }
return null; return null;
} }
public boolean allowTypeWhenOverflow(BlobType type) {
return type == this;
}
public static EnumSet<BlobType> getAvailable() { public static EnumSet<BlobType> getAvailable() {
WhiteBox whiteBox = WhiteBox.getWhiteBox(); WhiteBox whiteBox = WhiteBox.getWhiteBox();
if (!whiteBox.getBooleanVMFlag("SegmentedCodeCache")) { if (!whiteBox.getBooleanVMFlag("SegmentedCodeCache")) {

View file

@ -39,6 +39,13 @@ public class CodeBlob {
} }
return result; return result;
} }
public static CodeBlob getCodeBlob(long addr) {
Object[] obj = WB.getCodeBlob(addr);
if (obj == null) {
return null;
}
return new CodeBlob(obj);
}
protected CodeBlob(Object[] obj) { protected CodeBlob(Object[] obj) {
assert obj.length == 3; assert obj.length == 3;
name = (String) obj[0]; name = (String) obj[0];