提交 e32a28a5 编写于 作者: D dholmes

Merge

......@@ -37,6 +37,7 @@
#include "runtime/os.hpp"
#include "utilities/debug.hpp"
#include "utilities/macros.hpp"
#include "utilities/exceptions.hpp"
#if INCLUDE_ALL_GCS
#include "gc_implementation/g1/concurrentMark.hpp"
......@@ -330,8 +331,18 @@ WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
WB_END
WB_ENTRY(jlong, WB_ReserveMemory(JNIEnv* env, jobject o, jlong size))
return (jlong)os::reserve_memory(size, NULL, 0);
WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o))
// static+volatile in order to force the read to happen
// (not be eliminated by the compiler)
static char c;
static volatile char* p;
p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0);
if (p == NULL) {
THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
}
c = *p;
WB_END
//Some convenience methods to deal with objects from java
......@@ -437,7 +448,7 @@ static JNINativeMethod methods[] = {
{CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable },
{CC"fullGC", CC"()V", (void*)&WB_FullGC },
{CC"reserveMemory", CC"(J)J", (void*)&WB_ReserveMemory },
{CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory },
};
#undef CC
......
......@@ -34,29 +34,20 @@
import com.oracle.java.testlibrary.*;
import java.lang.reflect.Field;
import sun.hotspot.WhiteBox;
import sun.misc.Unsafe;
public class ReserveMemory {
private static Unsafe getUnsafe() throws Exception {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe)f.get(null);
}
private static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().startsWith("win");
}
private static boolean isOsx() {
return System.getProperty("os.name").toLowerCase().startsWith("mac");
}
public static void main(String args[]) throws Exception {
if (args.length > 0) {
long address = WhiteBox.getWhiteBox().reserveMemory(4096);
System.out.println("Reserved memory at address: 0x" + Long.toHexString(address));
System.out.println("Will now read from the address, expecting a crash!");
int x = getUnsafe().getInt(address);
WhiteBox.getWhiteBox().readReservedMemory();
throw new Exception("Read of reserved/uncommitted memory unexpectedly succeeded, expected crash!");
}
......@@ -71,6 +62,8 @@ public class ReserveMemory {
OutputAnalyzer output = new OutputAnalyzer(pb.start());
if (isWindows()) {
output.shouldContain("EXCEPTION_ACCESS_VIOLATION");
} else if (isOsx()) {
output.shouldContain("SIGBUS");
} else {
output.shouldContain("SIGSEGV");
}
......
......@@ -115,7 +115,7 @@ public class WhiteBox {
public native boolean isInStringTable(String str);
// Memory
public native long reserveMemory(long size);
public native void readReservedMemory();
// force Full GC
public native void fullGC();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册