--- a/hotspot/src/cpu/sparc/vm/interpreterRT_sparc.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/cpu/sparc/vm/interpreterRT_sparc.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -237,7 +237,7 @@
// handle arguments
// Warning: We use reg arg slot 00 temporarily to return the RegArgSignature
// back to the code that pops the arguments into the CPU registers
- SlowSignatureHandler(m, (address)from, m->is_static() ? to+2 : to+1, to).iterate(UCONST64(-1));
+ SlowSignatureHandler(m, (address)from, m->is_static() ? to+2 : to+1, to).iterate((uint64_t)CONST64(-1));
// return result handler
return Interpreter::result_handler(m->result_type());
IRT_END
--- a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -60,10 +60,10 @@
static jlong fp_signmask_pool[(4+1)*2]; // 4*128bits(data) + 128bits(alignment)
// Static initialization during VM startup.
-static jlong *float_signmask_pool = double_quadword(&fp_signmask_pool[1*2], CONST64(0x7FFFFFFF7FFFFFFF), CONST64(0x7FFFFFFF7FFFFFFF));
-static jlong *double_signmask_pool = double_quadword(&fp_signmask_pool[2*2], CONST64(0x7FFFFFFFFFFFFFFF), CONST64(0x7FFFFFFFFFFFFFFF));
-static jlong *float_signflip_pool = double_quadword(&fp_signmask_pool[3*2], CONST64(0x8000000080000000), CONST64(0x8000000080000000));
-static jlong *double_signflip_pool = double_quadword(&fp_signmask_pool[4*2], CONST64(0x8000000000000000), CONST64(0x8000000000000000));
+static jlong *float_signmask_pool = double_quadword(&fp_signmask_pool[1*2], CONST64(0x7FFFFFFF7FFFFFFF), CONST64(0x7FFFFFFF7FFFFFFF));
+static jlong *double_signmask_pool = double_quadword(&fp_signmask_pool[2*2], CONST64(0x7FFFFFFFFFFFFFFF), CONST64(0x7FFFFFFFFFFFFFFF));
+static jlong *float_signflip_pool = double_quadword(&fp_signmask_pool[3*2], (jlong)UCONST64(0x8000000080000000), (jlong)UCONST64(0x8000000080000000));
+static jlong *double_signflip_pool = double_quadword(&fp_signmask_pool[4*2], (jlong)UCONST64(0x8000000000000000), (jlong)UCONST64(0x8000000000000000));
--- a/hotspot/src/cpu/x86/vm/c1_Runtime1_x86.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/cpu/x86/vm/c1_Runtime1_x86.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -1597,7 +1597,7 @@
__ movl(rdx, 0x80000000);
__ xorl(rax, rax);
#else
- __ mov64(rax, CONST64(0x8000000000000000));
+ __ mov64(rax, UCONST64(0x8000000000000000));
#endif // _LP64
__ jmp(do_return);
--- a/hotspot/src/cpu/x86/vm/interpreterRT_x86_32.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/cpu/x86/vm/interpreterRT_x86_32.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -135,7 +135,7 @@
methodHandle m(thread, (Method*)method);
assert(m->is_native(), "sanity check");
// handle arguments
- SlowSignatureHandler(m, (address)from, to + 1).iterate(UCONST64(-1));
+ SlowSignatureHandler(m, (address)from, to + 1).iterate((uint64_t)CONST64(-1));
// return result handler
return Interpreter::result_handler(m->result_type());
IRT_END
--- a/hotspot/src/cpu/x86/vm/interpreterRT_x86_64.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/cpu/x86/vm/interpreterRT_x86_64.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -487,7 +487,7 @@
assert(m->is_native(), "sanity check");
// handle arguments
- SlowSignatureHandler(m, (address)from, to + 1).iterate(UCONST64(-1));
+ SlowSignatureHandler(m, (address)from, to + 1).iterate((uint64_t)CONST64(-1));
// return result handler
return Interpreter::result_handler(m->result_type());
--- a/hotspot/src/cpu/zero/vm/interpreterRT_zero.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/cpu/zero/vm/interpreterRT_zero.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -155,7 +155,7 @@
intptr_t *buf = (intptr_t *) stack->alloc(required_words * wordSize);
SlowSignatureHandlerGenerator sshg(methodHandle(thread, method), buf);
- sshg.generate(UCONST64(-1));
+ sshg.generate((uint64_t)CONST64(-1));
SignatureHandler *handler = sshg.handler();
handler->finalize();
--- a/hotspot/src/os/aix/vm/os_aix.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/aix/vm/os_aix.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -1641,7 +1641,8 @@
char* rp = realpath((char *)dlinfo.dli_fname, buf);
assert(rp != NULL, "error in realpath(): maybe the 'path' argument is too long?");
- strcpy(saved_jvm_path, buf);
+ strncpy(saved_jvm_path, buf, sizeof(saved_jvm_path));
+ saved_jvm_path[sizeof(saved_jvm_path) - 1] = '\0';
}
void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
--- a/hotspot/src/os/aix/vm/perfMemory_aix.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/aix/vm/perfMemory_aix.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -506,6 +506,7 @@
if (!is_directory_secure(dirname)) {
// the directory is not a secure directory
+ os::closedir(dirp);
return;
}
@@ -853,6 +854,9 @@
//
if (!is_directory_secure(dirname)) {
FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
+ if (luser != user) {
+ FREE_C_HEAP_ARRAY(char, luser, mtInternal);
+ }
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
"Process not found");
}
--- a/hotspot/src/os/bsd/vm/os_bsd.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -1875,6 +1875,7 @@
}
strncpy(saved_jvm_path, buf, MAXPATHLEN);
+ saved_jvm_path[MAXPATHLEN - 1] = '\0';
}
void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
--- a/hotspot/src/os/bsd/vm/perfMemory_bsd.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/bsd/vm/perfMemory_bsd.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -506,6 +506,7 @@
if (!is_directory_secure(dirname)) {
// the directory is not a secure directory
+ os::closedir(dirp);
return;
}
@@ -872,6 +873,9 @@
//
if (!is_directory_secure(dirname)) {
FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
+ if (luser != user) {
+ FREE_C_HEAP_ARRAY(char, luser, mtInternal);
+ }
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
"Process not found");
}
--- a/hotspot/src/os/linux/vm/os_linux.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/linux/vm/os_linux.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -355,7 +355,10 @@
// Found the full path to libjvm.so.
// Now cut the path to <java_home>/jre if we can.
- *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
+ pslash = strrchr(buf, '/');
+ if (pslash != NULL) {
+ *pslash = '\0'; // Get rid of /libjvm.so.
+ }
pslash = strrchr(buf, '/');
if (pslash != NULL) {
*pslash = '\0'; // Get rid of /{client|server|hotspot}.
@@ -1194,7 +1197,7 @@
i = 0;
if (s) {
// Skip blank chars
- do s++; while (isspace(*s));
+ do { s++; } while (s && isspace(*s));
#define _UFM UINTX_FORMAT
#define _DFM INTX_FORMAT
@@ -2343,6 +2346,9 @@
// Check the current module name "libjvm.so".
p = strrchr(buf, '/');
+ if (p == NULL) {
+ return;
+ }
assert(strstr(p, "/libjvm") == p, "invalid library name");
rp = realpath(java_home_var, buf);
@@ -2376,6 +2382,7 @@
}
strncpy(saved_jvm_path, buf, MAXPATHLEN);
+ saved_jvm_path[MAXPATHLEN - 1] = '\0';
}
void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
@@ -5314,7 +5321,7 @@
if (s == NULL) return -1;
// Skip blank chars
- do s++; while (isspace(*s));
+ do { s++; } while (s && isspace(*s));
count = sscanf(s,"%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu",
&cdummy, &idummy, &idummy, &idummy, &idummy, &idummy,
--- a/hotspot/src/os/linux/vm/perfMemory_linux.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/linux/vm/perfMemory_linux.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -506,6 +506,7 @@
if (!is_directory_secure(dirname)) {
// the directory is not a secure directory
+ os::closedir(dirp);
return;
}
@@ -872,6 +873,9 @@
//
if (!is_directory_secure(dirname)) {
FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
+ if (luser != user) {
+ FREE_C_HEAP_ARRAY(char, luser, mtInternal);
+ }
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
"Process not found");
}
--- a/hotspot/src/os/posix/vm/os_posix.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/posix/vm/os_posix.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -663,7 +663,10 @@
}
}
- jio_snprintf(out, outlen, ret);
+ if (out && outlen > 0) {
+ strncpy(out, ret, outlen);
+ out[outlen - 1] = '\0';
+ }
return out;
}
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -2221,6 +2221,7 @@
}
strncpy(saved_jvm_path, buf, MAXPATHLEN);
+ saved_jvm_path[MAXPATHLEN - 1] = '\0';
}
--- a/hotspot/src/os/solaris/vm/perfMemory_solaris.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/solaris/vm/perfMemory_solaris.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -545,6 +545,7 @@
if (!is_directory_secure(dirname)) {
// the directory is not a secure directory
+ os::closedir(dirp);
return;
}
@@ -890,6 +891,9 @@
//
if (!is_directory_secure(dirname)) {
FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
+ if (luser != user) {
+ FREE_C_HEAP_ARRAY(char, luser, mtInternal);
+ }
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
"Process not found");
}
--- a/hotspot/src/os/windows/vm/attachListener_windows.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/windows/vm/attachListener_windows.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -30,6 +30,7 @@
#include <windows.h>
#include <signal.h> // SIGBREAK
+#include <stdio.h>
// The AttachListener thread services a queue of operations. It blocks in the dequeue
// function until an operation is enqueued. A client enqueues an operation by creating
@@ -269,6 +270,7 @@
if (hPipe != INVALID_HANDLE_VALUE) {
// shouldn't happen as there is a pipe created per operation
if (::GetLastError() == ERROR_PIPE_BUSY) {
+ ::CloseHandle(hPipe);
return INVALID_HANDLE_VALUE;
}
}
@@ -313,7 +315,8 @@
BOOL fSuccess;
char msg[32];
- sprintf(msg, "%d\n", result);
+ _snprintf(msg, sizeof(msg), "%d\n", result);
+ msg[sizeof(msg) - 1] = '\0';
fSuccess = write_pipe(hPipe, msg, (int)strlen(msg));
if (fSuccess) {
--- a/hotspot/src/os/windows/vm/os_windows.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/os/windows/vm/os_windows.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -96,7 +96,7 @@
#include <vdmdbg.h>
// for timer info max values which include all bits
-#define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
+#define ALL_64_BITS CONST64(-1)
// For DLL loading/load error detection
// Values of PE COFF
@@ -211,6 +211,7 @@
}
strcpy(home_path, home_dir);
Arguments::set_java_home(home_path);
+ FREE_C_HEAP_ARRAY(char, home_path, mtInternal);
dll_path = NEW_C_HEAP_ARRAY(char, strlen(home_dir) + strlen(bin) + 1,
mtInternal);
@@ -220,6 +221,7 @@
strcpy(dll_path, home_dir);
strcat(dll_path, bin);
Arguments::set_dll_dir(dll_path);
+ FREE_C_HEAP_ARRAY(char, dll_path, mtInternal);
if (!set_boot_path('\\', ';')) {
return;
@@ -297,6 +299,9 @@
char * buf = NEW_C_HEAP_ARRAY(char, len, mtInternal);
sprintf(buf, "%s%s", Arguments::get_java_home(), ENDORSED_DIR);
Arguments::set_endorsed_dirs(buf);
+ // (Arguments::set_endorsed_dirs() calls SystemProperty::set_value(), which
+ // duplicates the input.)
+ FREE_C_HEAP_ARRAY(char, buf, mtInternal);
#undef ENDORSED_DIR
}
@@ -1834,6 +1839,7 @@
GetModuleFileName(vm_lib_handle, buf, buflen);
}
strncpy(saved_jvm_path, buf, MAX_PATH);
+ saved_jvm_path[MAX_PATH - 1] = '\0';
}
@@ -3746,8 +3752,12 @@
// search system directory
if ((size = GetSystemDirectory(path, pathLen)) > 0) {
- strcat(path, "\\");
- strcat(path, name);
+ if (size >= pathLen) {
+ return NULL; // truncated
+ }
+ if (jio_snprintf(path + size, pathLen - size, "\\%s", name) == -1) {
+ return NULL; // truncated
+ }
if ((result = (HINSTANCE)os::dll_load(path, ebuf, ebuflen)) != NULL) {
return result;
}
@@ -3755,8 +3765,12 @@
// try Windows directory
if ((size = GetWindowsDirectory(path, pathLen)) > 0) {
- strcat(path, "\\");
- strcat(path, name);
+ if (size >= pathLen) {
+ return NULL; // truncated
+ }
+ if (jio_snprintf(path + size, pathLen - size, "\\%s", name) == -1) {
+ return NULL; // truncated
+ }
if ((result = (HINSTANCE)os::dll_load(path, ebuf, ebuflen)) != NULL) {
return result;
}
--- a/hotspot/src/share/vm/memory/metaspaceShared.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/memory/metaspaceShared.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -714,12 +714,17 @@
int class_list_path_len = (int)strlen(class_list_path_str);
if (class_list_path_len >= 3) {
if (strcmp(class_list_path_str + class_list_path_len - 3, "lib") != 0) {
- strcat(class_list_path_str, os::file_separator());
- strcat(class_list_path_str, "lib");
+ if (class_list_path_len < JVM_MAXPATHLEN - 4) {
+ strncat(class_list_path_str, os::file_separator(), 1);
+ strncat(class_list_path_str, "lib", 3);
+ }
}
}
- strcat(class_list_path_str, os::file_separator());
- strcat(class_list_path_str, "classlist");
+ class_list_path_len = (int)strlen(class_list_path_str);
+ if (class_list_path_len < JVM_MAXPATHLEN - 10) {
+ strncat(class_list_path_str, os::file_separator(), 1);
+ strncat(class_list_path_str, "classlist", 9);
+ }
class_list_path = class_list_path_str;
} else {
class_list_path = SharedClassListFile;
--- a/hotspot/src/share/vm/oops/constMethod.hpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/oops/constMethod.hpp Thu Nov 06 01:31:31 2014 +0000
@@ -277,7 +277,7 @@
bool has_stackmap_table() const { return _stackmap_data != NULL; }
void init_fingerprint() {
- const uint64_t initval = CONST64(0x8000000000000000);
+ const uint64_t initval = UCONST64(0x8000000000000000);
_fingerprint = initval;
}
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -2499,7 +2499,7 @@
// If this is an anonymous class, append a hash to make the name unique
if (is_anonymous()) {
intptr_t hash = (java_mirror() != NULL) ? java_mirror()->identity_hash() : 0;
- sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash);
+ jio_snprintf(hash_buf, sizeof(hash_buf), "/" UINTX_FORMAT, (uintx)hash);
hash_len = (int)strlen(hash_buf);
}
--- a/hotspot/src/share/vm/opto/mulnode.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/opto/mulnode.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -610,7 +610,7 @@
// convert masks which would cause a sign extension of the integer
// value. This check includes UI2L masks (0x00000000FFFFFFFF) which
// would be optimized away later in Identity.
- if (op == Op_ConvI2L && (mask & CONST64(0xFFFFFFFF80000000)) == 0) {
+ if (op == Op_ConvI2L && (mask & UCONST64(0xFFFFFFFF80000000)) == 0) {
Node* andi = new AndINode(in1->in(1), phase->intcon(mask));
andi = phase->transform(andi);
return new ConvI2LNode(andi);
--- a/hotspot/src/share/vm/prims/jni.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/prims/jni.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -951,8 +951,9 @@
// Optimized path if we have the bitvector form of signature
void iterate( uint64_t fingerprint ) {
- if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate();// Must be too many arguments
- else {
+ if (fingerprint == (uint64_t)CONST64(-1)) {
+ SignatureIterator::iterate(); // Must be too many arguments
+ } else {
_return_type = (BasicType)((fingerprint >> static_feature_size) &
result_feature_mask);
@@ -1022,8 +1023,9 @@
// Optimized path if we have the bitvector form of signature
void iterate( uint64_t fingerprint ) {
- if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate(); // Must be too many arguments
- else {
+ if (fingerprint == (uint64_t)CONST64(-1)) {
+ SignatureIterator::iterate(); // Must be too many arguments
+ } else {
_return_type = (BasicType)((fingerprint >> static_feature_size) &
result_feature_mask);
assert(fingerprint, "Fingerprint should not be 0");
--- a/hotspot/src/share/vm/prims/jvm.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/prims/jvm.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -2583,7 +2583,14 @@
int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
// see bug 4399518, 4417214
if ((intptr_t)count <= 0) return -1;
- return vsnprintf(str, count, fmt, args);
+
+ int result = vsnprintf(str, count, fmt, args);
+ if ((result > 0 && (size_t)result >= count) || result == -1) {
+ str[count - 1] = '\0';
+ result = -1;
+ }
+
+ return result;
}
ATTRIBUTE_PRINTF(3, 0)
--- a/hotspot/src/share/vm/prims/unsafe.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/prims/unsafe.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -802,8 +802,7 @@
static inline void throw_new(JNIEnv *env, const char *ename) {
char buf[100];
- strcpy(buf, "java/lang/");
- strcat(buf, ename);
+ jio_snprintf(buf, 100, "%s%s", "java/lang/", ename);
jclass cls = env->FindClass(buf);
if (env->ExceptionCheck()) {
env->ExceptionClear();
--- a/hotspot/src/share/vm/prims/whitebox.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/prims/whitebox.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -282,7 +282,7 @@
// NMT picks it up correctly
WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size))
jlong addr = 0;
- addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
+ addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
return addr;
WB_END
@@ -291,7 +291,7 @@
WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack))
address pc = (address)(size_t)pseudo_stack;
NativeCallStack stack(&pc, 1);
- return (jlong)os::malloc(size, mtTest, stack);
+ return (jlong)(uintptr_t)os::malloc(size, mtTest, stack);
WB_END
// Free the memory allocated by NMTAllocTest
@@ -326,15 +326,6 @@
return MemTracker::tracking_level() == NMT_detail;
WB_END
-WB_ENTRY(void, WB_NMTOverflowHashBucket(JNIEnv* env, jobject o, jlong num))
- address pc = (address)1;
- for (jlong index = 0; index < num; index ++) {
- NativeCallStack stack(&pc, 1);
- os::malloc(0, mtTest, stack);
- pc += MallocSiteTable::hash_buckets();
- }
-WB_END
-
WB_ENTRY(jboolean, WB_NMTChangeTrackingLevel(JNIEnv* env))
// Test that we can downgrade NMT levels but not upgrade them.
if (MemTracker::tracking_level() == NMT_off) {
@@ -365,6 +356,12 @@
return MemTracker::tracking_level() == NMT_minimal;
}
WB_END
+
+WB_ENTRY(jint, WB_NMTGetHashSize(JNIEnv* env, jobject o))
+ int hash_size = MallocSiteTable::hash_buckets();
+ assert(hash_size > 0, "NMT hash_size should be > 0");
+ return (jint)hash_size;
+WB_END
#endif // INCLUDE_NMT
static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) {
@@ -998,9 +995,9 @@
{CC"NMTCommitMemory", CC"(JJ)V", (void*)&WB_NMTCommitMemory },
{CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory },
{CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory },
- {CC"NMTOverflowHashBucket", CC"(J)V", (void*)&WB_NMTOverflowHashBucket},
{CC"NMTIsDetailSupported",CC"()Z", (void*)&WB_NMTIsDetailSupported},
{CC"NMTChangeTrackingLevel", CC"()Z", (void*)&WB_NMTChangeTrackingLevel},
+ {CC"NMTGetHashSize", CC"()I", (void*)&WB_NMTGetHashSize },
#endif // INCLUDE_NMT
{CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll },
{CC"deoptimizeMethod", CC"(Ljava/lang/reflect/Executable;Z)I",
--- a/hotspot/src/share/vm/runtime/globals.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/runtime/globals.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -28,6 +28,7 @@
#include "runtime/arguments.hpp"
#include "runtime/globals.hpp"
#include "runtime/globals_extension.hpp"
+#include "runtime/os.hpp"
#include "utilities/ostream.hpp"
#include "utilities/macros.hpp"
#include "utilities/top.hpp"
@@ -818,15 +819,12 @@
trace_flag_changed<EventStringFlagChanged, const char*>(name, old_value, *value, origin);
char* new_value = NULL;
if (*value != NULL) {
- new_value = NEW_C_HEAP_ARRAY(char, strlen(*value)+1, mtInternal);
- strcpy(new_value, *value);
+ new_value = os::strdup_check_oom(*value);
}
result->set_ccstr(new_value);
if (result->is_default() && old_value != NULL) {
// Prior value is NOT heap allocated, but was a literal constant.
- char* old_value_to_free = NEW_C_HEAP_ARRAY(char, strlen(old_value)+1, mtInternal);
- strcpy(old_value_to_free, old_value);
- old_value = old_value_to_free;
+ old_value = os::strdup_check_oom(old_value);
}
*value = old_value;
result->set_origin(origin);
@@ -838,8 +836,7 @@
guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
ccstr old_value = faddr->get_ccstr();
trace_flag_changed<EventStringFlagChanged, const char*>(faddr->_name, old_value, value, origin);
- char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1, mtInternal);
- strcpy(new_value, value);
+ char* new_value = os::strdup_check_oom(value);
faddr->set_ccstr(new_value);
if (!faddr->is_default() && old_value != NULL) {
// Prior value is heap allocated so free it.
--- a/hotspot/src/share/vm/runtime/java.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/runtime/java.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -705,25 +705,35 @@
}
void JDK_Version::to_string(char* buffer, size_t buflen) const {
+ assert(buffer && buflen > 0, "call with useful buffer");
size_t index = 0;
+
if (!is_valid()) {
jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
} else if (is_partially_initialized()) {
jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0");
} else {
- index += jio_snprintf(
+ int rc = jio_snprintf(
&buffer[index], buflen - index, "%d.%d", _major, _minor);
+ if (rc == -1) return;
+ index += rc;
if (_micro > 0) {
- index += jio_snprintf(&buffer[index], buflen - index, ".%d", _micro);
+ rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro);
}
if (_update > 0) {
- index += jio_snprintf(&buffer[index], buflen - index, "_%02d", _update);
+ rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update);
+ if (rc == -1) return;
+ index += rc;
}
if (_special > 0) {
- index += jio_snprintf(&buffer[index], buflen - index, "%c", _special);
+ rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special);
+ if (rc == -1) return;
+ index += rc;
}
if (_build > 0) {
- index += jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build);
+ rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build);
+ if (rc == -1) return;
+ index += rc;
}
}
}
--- a/hotspot/src/share/vm/runtime/os.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/runtime/os.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -571,17 +571,6 @@
NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
-#if INCLUDE_NMT
- // NMT can not track malloc allocation size > MAX_MALLOC_SIZE, which is
- // (1GB - 1) on 32-bit system. It is not an issue on 64-bit system, where
- // MAX_MALLOC_SIZE = ((1 << 62) - 1).
- // VM code does not have such large malloc allocation. However, it can come
- // Unsafe call.
- if (MemTracker::tracking_level() >= NMT_summary && size > MAX_MALLOC_SIZE) {
- return NULL;
- }
-#endif
-
#ifdef ASSERT
// checking for the WatcherThread and crash_protection first
// since os::malloc can be called when the libjvm.{dll,so} is
@@ -652,12 +641,6 @@
}
void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCallStack& stack) {
-#if INCLUDE_NMT
- // See comments in os::malloc() above
- if (MemTracker::tracking_level() >= NMT_summary && size > MAX_MALLOC_SIZE) {
- return NULL;
- }
-#endif
#ifndef ASSERT
NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
--- a/hotspot/src/share/vm/runtime/signature.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/runtime/signature.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -158,7 +158,7 @@
uint64_t saved_fingerprint = fingerprint;
// Check for too many arguments
- if ( fingerprint == UCONST64(-1) ) {
+ if (fingerprint == (uint64_t)CONST64(-1)) {
SignatureIterator::iterate_parameters();
return;
}
--- a/hotspot/src/share/vm/runtime/signature.hpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/runtime/signature.hpp Thu Nov 06 01:31:31 2014 +0000
@@ -243,7 +243,7 @@
}
if (mh->size_of_parameters() > max_size_of_parameters ) {
- _fingerprint = UCONST64(-1);
+ _fingerprint = (uint64_t)CONST64(-1);
mh->constMethod()->set_fingerprint(_fingerprint);
return _fingerprint;
}
--- a/hotspot/src/share/vm/runtime/thread.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/runtime/thread.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -3639,7 +3639,7 @@
if (!agent->valid()) {
char buffer[JVM_MAXPATHLEN];
- char ebuf[1024];
+ char ebuf[1024] = "";
const char *name = agent->name();
const char *msg = "Could not find agent library ";
--- a/hotspot/src/share/vm/services/mallocTracker.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/services/mallocTracker.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -72,7 +72,7 @@
MallocMemorySummary::record_free(size(), flags());
MallocMemorySummary::record_free_malloc_header(sizeof(MallocHeader));
- if (tracking_level() == NMT_detail) {
+ if (MemTracker::tracking_level() == NMT_detail) {
MallocSiteTable::deallocation_at(size(), _bucket_idx, _pos_idx);
}
}
@@ -128,36 +128,18 @@
}
// Uses placement global new operator to initialize malloc header
- switch(level) {
- case NMT_off:
- return malloc_base;
- case NMT_minimal: {
- MallocHeader* hdr = ::new (malloc_base) MallocHeader();
- break;
- }
- case NMT_summary: {
- assert(size <= MAX_MALLOC_SIZE, "malloc size overrun for NMT");
- header = ::new (malloc_base) MallocHeader(size, flags);
- break;
- }
- case NMT_detail: {
- assert(size <= MAX_MALLOC_SIZE, "malloc size overrun for NMT");
- header = ::new (malloc_base) MallocHeader(size, flags, stack);
- break;
- }
- default:
- ShouldNotReachHere();
+
+ if (level == NMT_off) {
+ return malloc_base;
}
+
+ header = ::new (malloc_base)MallocHeader(size, flags, stack, level);
memblock = (void*)((char*)malloc_base + sizeof(MallocHeader));
// The alignment check: 8 bytes alignment for 32 bit systems.
// 16 bytes alignment for 64-bit systems.
assert(((size_t)memblock & (sizeof(size_t) * 2 - 1)) == 0, "Alignment check");
- // Sanity check
- assert(get_memory_tracking_level(memblock) == level,
- "Wrong tracking level");
-
#ifdef ASSERT
if (level > NMT_minimal) {
// Read back
--- a/hotspot/src/share/vm/services/mallocTracker.hpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/services/mallocTracker.hpp Thu Nov 06 01:31:31 2014 +0000
@@ -239,68 +239,46 @@
class MallocHeader VALUE_OBJ_CLASS_SPEC {
#ifdef _LP64
- size_t _size : 62;
- size_t _level : 2;
+ size_t _size : 64;
size_t _flags : 8;
size_t _pos_idx : 16;
size_t _bucket_idx: 40;
#define MAX_MALLOCSITE_TABLE_SIZE ((size_t)1 << 40)
#define MAX_BUCKET_LENGTH ((size_t)(1 << 16))
-#define MAX_MALLOC_SIZE (((size_t)1 << 62) - 1)
#else
- size_t _size : 30;
- size_t _level : 2;
+ size_t _size : 32;
size_t _flags : 8;
size_t _pos_idx : 8;
size_t _bucket_idx: 16;
#define MAX_MALLOCSITE_TABLE_SIZE ((size_t)(1 << 16))
#define MAX_BUCKET_LENGTH ((size_t)(1 << 8))
-// Max malloc size = 1GB - 1 on 32 bit system, such has total 4GB memory
-#define MAX_MALLOC_SIZE ((size_t)(1 << 30) - 1)
#endif // _LP64
public:
- // Summary tracking header
- MallocHeader(size_t size, MEMFLAGS flags) {
- assert(sizeof(MallocHeader) == sizeof(void*) * 2,
- "Wrong header size");
-
- _level = NMT_summary;
- _flags = flags;
- set_size(size);
- MallocMemorySummary::record_malloc(size, flags);
- MallocMemorySummary::record_new_malloc_header(sizeof(MallocHeader));
- }
- // Detail tracking header
- MallocHeader(size_t size, MEMFLAGS flags, const NativeCallStack& stack) {
+ MallocHeader(size_t size, MEMFLAGS flags, const NativeCallStack& stack, NMT_TrackingLevel level) {
assert(sizeof(MallocHeader) == sizeof(void*) * 2,
"Wrong header size");
- _level = NMT_detail;
+ if (level == NMT_minimal) {
+ return;
+ }
+
_flags = flags;
set_size(size);
- size_t bucket_idx;
- size_t pos_idx;
- if (record_malloc_site(stack, size, &bucket_idx, &pos_idx)) {
- assert(bucket_idx <= MAX_MALLOCSITE_TABLE_SIZE, "Overflow bucket index");
- assert(pos_idx <= MAX_BUCKET_LENGTH, "Overflow bucket position index");
- _bucket_idx = bucket_idx;
- _pos_idx = pos_idx;
+ if (level == NMT_detail) {
+ size_t bucket_idx;
+ size_t pos_idx;
+ if (record_malloc_site(stack, size, &bucket_idx, &pos_idx)) {
+ assert(bucket_idx <= MAX_MALLOCSITE_TABLE_SIZE, "Overflow bucket index");
+ assert(pos_idx <= MAX_BUCKET_LENGTH, "Overflow bucket position index");
+ _bucket_idx = bucket_idx;
+ _pos_idx = pos_idx;
+ }
}
+
MallocMemorySummary::record_malloc(size, flags);
MallocMemorySummary::record_new_malloc_header(sizeof(MallocHeader));
}
- // Minimal tracking header
- MallocHeader() {
- assert(sizeof(MallocHeader) == sizeof(void*) * 2,
- "Wrong header size");
-
- _level = (unsigned short)NMT_minimal;
- }
-
- inline NMT_TrackingLevel tracking_level() const {
- return (NMT_TrackingLevel)_level;
- }
inline size_t size() const { return _size; }
inline MEMFLAGS flags() const { return (MEMFLAGS)_flags; }
@@ -311,7 +289,6 @@
private:
inline void set_size(size_t size) {
- assert(size <= MAX_MALLOC_SIZE, "Malloc size too large, should use virtual memory?");
_size = size;
}
bool record_malloc_site(const NativeCallStack& stack, size_t size,
@@ -347,10 +324,6 @@
// Record free on specified memory block
static void* record_free(void* memblock);
- // Get tracking level of specified memory block
- static inline NMT_TrackingLevel get_memory_tracking_level(void* memblock);
-
-
// Offset memory address to header address
static inline void* get_base(void* memblock);
static inline void* get_base(void* memblock, NMT_TrackingLevel level) {
@@ -361,16 +334,12 @@
// Get memory size
static inline size_t get_size(void* memblock) {
MallocHeader* header = malloc_header(memblock);
- assert(header->tracking_level() >= NMT_summary,
- "Wrong tracking level");
return header->size();
}
// Get memory type
static inline MEMFLAGS get_flags(void* memblock) {
MallocHeader* header = malloc_header(memblock);
- assert(header->tracking_level() >= NMT_summary,
- "Wrong tracking level");
return header->flags();
}
@@ -394,7 +363,6 @@
static inline MallocHeader* malloc_header(void *memblock) {
assert(memblock != NULL, "NULL pointer");
MallocHeader* header = (MallocHeader*)((char*)memblock - sizeof(MallocHeader));
- assert(header->tracking_level() >= NMT_minimal, "Bad header");
return header;
}
};
--- a/hotspot/src/share/vm/services/mallocTracker.inline.hpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/services/mallocTracker.inline.hpp Thu Nov 06 01:31:31 2014 +0000
@@ -28,13 +28,6 @@
#include "services/mallocTracker.hpp"
#include "services/memTracker.hpp"
-inline NMT_TrackingLevel MallocTracker::get_memory_tracking_level(void* memblock) {
- assert(memblock != NULL, "Sanity check");
- if (MemTracker::tracking_level() == NMT_off) return NMT_off;
- MallocHeader* header = malloc_header(memblock);
- return header->tracking_level();
-}
-
inline void* MallocTracker::get_base(void* memblock){
return get_base(memblock, MemTracker::tracking_level());
}
--- a/hotspot/src/share/vm/services/management.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/services/management.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -1333,7 +1333,7 @@
GrowableArray<oop>* locked_monitors = frame->locked_monitors();
for (j = 0; j < len; j++) {
oop monitor = locked_monitors->at(j);
- assert(monitor != NULL && monitor->is_instance(), "must be a Java object");
+ assert(monitor != NULL, "must be a Java object");
monitors_array->obj_at_put(count, monitor);
depths_array->int_at_put(count, depth);
count++;
@@ -1343,7 +1343,7 @@
GrowableArray<oop>* jni_locked_monitors = stacktrace->jni_locked_monitors();
for (j = 0; j < jni_locked_monitors->length(); j++) {
oop object = jni_locked_monitors->at(j);
- assert(object != NULL && object->is_instance(), "must be a Java object");
+ assert(object != NULL, "must be a Java object");
monitors_array->obj_at_put(count, object);
// Monitor locked via JNI MonitorEnter call doesn't have stack depth info
depths_array->int_at_put(count, -1);
--- a/hotspot/src/share/vm/services/threadService.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/services/threadService.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -597,7 +597,7 @@
GrowableArray<oop>* locked_monitors = frame->locked_monitors();
for (int j = 0; j < len; j++) {
oop monitor = locked_monitors->at(j);
- assert(monitor != NULL && monitor->is_instance(), "must be a Java object");
+ assert(monitor != NULL, "must be a Java object");
if (monitor == object) {
found = true;
break;
--- a/hotspot/src/share/vm/utilities/globalDefinitions.hpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/utilities/globalDefinitions.hpp Thu Nov 06 01:31:31 2014 +0000
@@ -1048,7 +1048,7 @@
const int badResourceValue = 0xAB; // value used to zap resource area
const int freeBlockPad = 0xBA; // value used to pad freed blocks.
const int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks.
-const intptr_t badJNIHandleVal = (intptr_t) CONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area
+const intptr_t badJNIHandleVal = (intptr_t) UCONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area
const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC
const juint badMetaWordVal = 0xBAADFADE; // value used to zap metadata heap after GC
const int badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation
--- a/hotspot/src/share/vm/utilities/globalDefinitions_visCPP.hpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/utilities/globalDefinitions_visCPP.hpp Thu Nov 06 01:31:31 2014 +0000
@@ -151,11 +151,11 @@
// Constant for jlong (specifying an long long constant is C++ compiler specific)
// Build a 64bit integer constant on with Visual C++
-#define CONST64(x) (x ## i64)
-#define UCONST64(x) ((uint64_t)CONST64(x))
+#define CONST64(x) (x ## i64)
+#define UCONST64(x) (x ## ui64)
-const jlong min_jlong = CONST64(0x8000000000000000);
-const jlong max_jlong = CONST64(0x7fffffffffffffff);
+const jlong min_jlong = (jlong)UCONST64(0x8000000000000000);
+const jlong max_jlong = CONST64(0x7fffffffffffffff);
//----------------------------------------------------------------------------------------------------
// Miscellaneous
--- a/hotspot/src/share/vm/utilities/ostream.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/utilities/ostream.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -76,6 +76,8 @@
const char* format, va_list ap,
bool add_cr,
size_t& result_len) {
+ assert(buflen >= 2, "buffer too small");
+
const char* result;
if (add_cr) buflen--;
if (!strchr(format, '%')) {
@@ -88,14 +90,21 @@
result = va_arg(ap, const char*);
result_len = strlen(result);
if (add_cr && result_len >= buflen) result_len = buflen-1; // truncate
- } else if (vsnprintf(buffer, buflen, format, ap) >= 0) {
+ } else {
+ // Handle truncation:
+ // posix: upon truncation, vsnprintf returns number of bytes which
+ // would have been written (excluding terminating zero) had the buffer
+ // been large enough
+ // windows: upon truncation, vsnprintf returns -1
+ const int written = vsnprintf(buffer, buflen, format, ap);
result = buffer;
- result_len = strlen(result);
- } else {
- DEBUG_ONLY(warning("increase O_BUFLEN in ostream.hpp -- output truncated");)
- result = buffer;
- result_len = buflen - 1;
- buffer[result_len] = 0;
+ if (written < (int) buflen && written >= 0) {
+ result_len = written;
+ } else {
+ DEBUG_ONLY(warning("increase O_BUFLEN in ostream.hpp -- output truncated");)
+ result_len = buflen - 1;
+ buffer[result_len] = 0;
+ }
}
if (add_cr) {
if (result != buffer) {
--- a/hotspot/src/share/vm/utilities/vmError.cpp Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/src/share/vm/utilities/vmError.cpp Thu Nov 06 01:31:31 2014 +0000
@@ -975,11 +975,13 @@
// Run error reporting to determine whether or not to report the crash.
if (!transmit_report_done && should_report_bug(first_error->_id)) {
transmit_report_done = true;
- FILE* hs_err = os::open(log.fd(), "r");
+ const int fd2 = ::dup(log.fd());
+ FILE* const hs_err = ::fdopen(fd2, "r");
if (NULL != hs_err) {
ErrorReporter er;
er.call(hs_err, buffer, O_BUFLEN);
}
+ ::fclose(hs_err);
}
if (log.fd() != defaultStream::output_fd()) {
--- a/hotspot/test/TEST.ROOT Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/test/TEST.ROOT Thu Nov 06 01:31:31 2014 +0000
@@ -30,3 +30,4 @@
keys=cte_test jcmd nmt regression gc stress
groups=TEST.groups [closed/TEST.groups]
+requires.properties=sun.arch.data.model
--- a/hotspot/test/TEST.groups Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/test/TEST.groups Thu Nov 06 01:31:31 2014 +0000
@@ -87,7 +87,6 @@
runtime/NMT/SummarySanityCheck.java \
runtime/NMT/ThreadedMallocTestType.java \
runtime/NMT/ThreadedVirtualAllocTestType.java \
- runtime/NMT/UnsafeMallocLimit.java \
runtime/NMT/VirtualAllocCommitUncommitRecommit.java \
runtime/NMT/VirtualAllocTestType.java \
runtime/RedefineObject/TestRedefineObject.java \
--- a/hotspot/test/runtime/7194254/Test7194254.java Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/test/runtime/7194254/Test7194254.java Thu Nov 06 01:31:31 2014 +0000
@@ -27,6 +27,7 @@
* @summary Creates several threads with different java priorities and checks
* whether jstack reports correct priorities for them.
*
+ * @ignore 8060219
* @run main Test7194254
*/
--- a/hotspot/test/runtime/NMT/MallocSiteHashOverflow.java Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/test/runtime/NMT/MallocSiteHashOverflow.java Thu Nov 06 01:31:31 2014 +0000
@@ -24,41 +24,56 @@
/*
* @test
* @summary Test corner case that overflows malloc site hashtable bucket
+ * @requires sun.arch.data.model == "32"
* @key nmt jcmd stress
* @library /testlibrary /testlibrary/whitebox
- * @ignore - This test is disabled since it will stress NMT and timeout during normal testing
+ * @ignore 8062870
* @build MallocSiteHashOverflow
* @run main ClassFileInstaller sun.hotspot.WhiteBox
- * @run main/othervm/timeout=480 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocSiteHashOverflow
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocSiteHashOverflow
*/
import com.oracle.java.testlibrary.*;
import sun.hotspot.WhiteBox;
public class MallocSiteHashOverflow {
- private static long K = 1024;
+
public static void main(String args[]) throws Exception {
- String vm_name = System.getProperty("java.vm.name");
+ // Size of entries based on malloc tracking header defined in mallocTracker.hpp
// For 32-bit systems, create 257 malloc sites with the same hash bucket to overflow a hash bucket
- // For 64-bit systems, create 64K + 1 malloc sites with the same hash bucket to overflow a hash bucket
long entries = 257;
- if (Platform.is64bit()) {
- entries = 64 * K + 1;
- }
OutputAnalyzer output;
WhiteBox wb = WhiteBox.getWhiteBox();
+ int MAX_HASH_SIZE = wb.NMTGetHashSize();
// Grab my own PID
String pid = Integer.toString(ProcessTools.getProcessId());
ProcessBuilder pb = new ProcessBuilder();
- wb.NMTOverflowHashBucket(entries);
-
- // Run 'jcmd <pid> VM.native_memory summary'
+ // Verify that current tracking level is "detail"
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
output = new OutputAnalyzer(pb.start());
- output.shouldContain("Tracking level has been downgraded due to lack of resources");
+ output.shouldContain("Native Memory Tracking Statistics");
+
+ // Attempt to cause NMT to downgrade tracking level by allocating small amounts
+ // of memory with random pseudo call stack
+ int pc = 1;
+ for (int i = 0; i < entries; i++) {
+ long addr = wb.NMTMallocWithPseudoStack(1, pc);
+ if (addr == 0) {
+ throw new RuntimeException("NMTMallocWithPseudoStack: out of memory");
+ }
+ // We free memory here since it doesn't affect pseudo malloc alloc site hash table entries
+ wb.NMTFree(addr);
+ pc += MAX_HASH_SIZE;
+ if (i == entries) {
+ // Verify that tracking has been downgraded
+ pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"});
+ output = new OutputAnalyzer(pb.start());
+ output.shouldContain("Tracking level has been downgraded due to lack of resources");
+ }
+ }
}
}
--- a/hotspot/test/runtime/NMT/UnsafeMallocLimit.java Wed Nov 05 13:00:59 2014 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * 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.
- */
-
-/*
- * @test
- * @bug 8055289
- * @library /testlibrary
- * @build UnsafeMallocLimit
- * @run main/othervm -Xmx32m -XX:NativeMemoryTracking=summary UnsafeMallocLimit
- */
-
-import com.oracle.java.testlibrary.*;
-import sun.misc.Unsafe;
-
-public class UnsafeMallocLimit {
-
- public static void main(String args[]) throws Exception {
- if (Platform.is32bit()) {
- Unsafe unsafe = Utils.getUnsafe();
- try {
- unsafe.allocateMemory(1 << 30);
- throw new RuntimeException("Did not get expected OOME");
- } catch (OutOfMemoryError e) {
- // Expected exception
- }
- } else {
- System.out.println("Test only valid on 32-bit platforms");
- }
- }
-}
--- a/hotspot/test/runtime/NMT/UnsafeMallocLimit2.java Wed Nov 05 13:00:59 2014 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
- * 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.
- */
-
-/*
- * @test
- * @bug 8058818
- * @library /testlibrary
- * @build UnsafeMallocLimit2
- * @run main/othervm -Xmx32m -XX:NativeMemoryTracking=off UnsafeMallocLimit2
- */
-
-import com.oracle.java.testlibrary.*;
-import sun.misc.Unsafe;
-
-public class UnsafeMallocLimit2 {
-
- public static void main(String args[]) throws Exception {
- if (Platform.is32bit()) {
- Unsafe unsafe = Utils.getUnsafe();
- try {
- // Allocate greater than MALLOC_MAX and likely won't fail to allocate,
- // so it hits the NMT code that asserted.
- // Test that this doesn't cause an assertion with NMT off.
- // The option above overrides if all the tests are run with NMT on.
- unsafe.allocateMemory(0x40000000);
- System.out.println("Allocation succeeded");
- } catch (OutOfMemoryError e) {
- System.out.println("Allocation failed");
- }
- } else {
- System.out.println("Test only valid on 32-bit platforms");
- }
- }
-}
--- a/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java Wed Nov 05 13:00:59 2014 -0800
+++ b/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java Thu Nov 06 01:31:31 2014 +0000
@@ -98,10 +98,10 @@
public native void NMTCommitMemory(long addr, long size);
public native void NMTUncommitMemory(long addr, long size);
public native void NMTReleaseMemory(long addr, long size);
- public native void NMTOverflowHashBucket(long num);
public native long NMTMallocWithPseudoStack(long size, int index);
public native boolean NMTIsDetailSupported();
public native boolean NMTChangeTrackingLevel();
+ public native int NMTGetHashSize();
// Compiler
public native void deoptimizeAll();