mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 03:24:38 +02:00
8013726: runtime/memory/ReserveMemory.java fails due to 'assert(bytes % os::vm_allocation_granularity() == 0) failed: reserve block size'
Fix regression test to work on all platforms Reviewed-by: ctornqvi, dholmes
This commit is contained in:
parent
a462587e4b
commit
de93893f4e
3 changed files with 22 additions and 18 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue