comparison src/share/vm/prims/unsafe.cpp @ 6197:d2a62e0f25eb

6995781: Native Memory Tracking (Phase 1) 7151532: DCmd for hotspot native memory tracking Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd Reviewed-by: acorn, coleenp, fparain
author zgu
date Thu, 28 Jun 2012 17:03:16 -0400
parents 12d38ffcba2a
children 9c9fb30d2b3b
comparison
equal deleted inserted replaced
6174:74533f63b116 6197:d2a62e0f25eb
594 } 594 }
595 if (sz == 0) { 595 if (sz == 0) {
596 return 0; 596 return 0;
597 } 597 }
598 sz = round_to(sz, HeapWordSize); 598 sz = round_to(sz, HeapWordSize);
599 void* x = os::malloc(sz); 599 void* x = os::malloc(sz, mtInternal);
600 if (x == NULL) { 600 if (x == NULL) {
601 THROW_0(vmSymbols::java_lang_OutOfMemoryError()); 601 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
602 } 602 }
603 //Copy::fill_to_words((HeapWord*)x, sz / HeapWordSize); 603 //Copy::fill_to_words((HeapWord*)x, sz / HeapWordSize);
604 return addr_to_java(x); 604 return addr_to_java(x);
614 if (sz == 0) { 614 if (sz == 0) {
615 os::free(p); 615 os::free(p);
616 return 0; 616 return 0;
617 } 617 }
618 sz = round_to(sz, HeapWordSize); 618 sz = round_to(sz, HeapWordSize);
619 void* x = (p == NULL) ? os::malloc(sz) : os::realloc(p, sz); 619 void* x = (p == NULL) ? os::malloc(sz, mtInternal) : os::realloc(p, sz, mtInternal);
620 if (x == NULL) { 620 if (x == NULL) {
621 THROW_0(vmSymbols::java_lang_OutOfMemoryError()); 621 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
622 } 622 }
623 return addr_to_java(x); 623 return addr_to_java(x);
624 UNSAFE_END 624 UNSAFE_END
875 if (length < 0) { 875 if (length < 0) {
876 throw_new(env, "ArrayIndexOutOfBoundsException"); 876 throw_new(env, "ArrayIndexOutOfBoundsException");
877 return 0; 877 return 0;
878 } 878 }
879 879
880 body = NEW_C_HEAP_ARRAY(jbyte, length); 880 body = NEW_C_HEAP_ARRAY(jbyte, length, mtInternal);
881 881
882 if (body == 0) { 882 if (body == 0) {
883 throw_new(env, "OutOfMemoryError"); 883 throw_new(env, "OutOfMemoryError");
884 return 0; 884 return 0;
885 } 885 }
891 891
892 if (name != NULL) { 892 if (name != NULL) {
893 uint len = env->GetStringUTFLength(name); 893 uint len = env->GetStringUTFLength(name);
894 int unicode_len = env->GetStringLength(name); 894 int unicode_len = env->GetStringLength(name);
895 if (len >= sizeof(buf)) { 895 if (len >= sizeof(buf)) {
896 utfName = NEW_C_HEAP_ARRAY(char, len + 1); 896 utfName = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
897 if (utfName == NULL) { 897 if (utfName == NULL) {
898 throw_new(env, "OutOfMemoryError"); 898 throw_new(env, "OutOfMemoryError");
899 goto free_body; 899 goto free_body;
900 } 900 }
901 } else { 901 } else {
911 } 911 }
912 912
913 result = JVM_DefineClass(env, utfName, loader, body, length, pd); 913 result = JVM_DefineClass(env, utfName, loader, body, length, pd);
914 914
915 if (utfName && utfName != buf) 915 if (utfName && utfName != buf)
916 FREE_C_HEAP_ARRAY(char, utfName); 916 FREE_C_HEAP_ARRAY(char, utfName, mtInternal);
917 917
918 free_body: 918 free_body:
919 FREE_C_HEAP_ARRAY(jbyte, body); 919 FREE_C_HEAP_ARRAY(jbyte, body, mtInternal);
920 return result; 920 return result;
921 } 921 }
922 } 922 }
923 923
924 924
1009 THROW_0(vmSymbols::java_lang_NullPointerException()); 1009 THROW_0(vmSymbols::java_lang_NullPointerException());
1010 } 1010 }
1011 1011
1012 jint length = typeArrayOop(JNIHandles::resolve_non_null(data))->length(); 1012 jint length = typeArrayOop(JNIHandles::resolve_non_null(data))->length();
1013 jint word_length = (length + sizeof(HeapWord)-1) / sizeof(HeapWord); 1013 jint word_length = (length + sizeof(HeapWord)-1) / sizeof(HeapWord);
1014 HeapWord* body = NEW_C_HEAP_ARRAY(HeapWord, word_length); 1014 HeapWord* body = NEW_C_HEAP_ARRAY(HeapWord, word_length, mtInternal);
1015 if (body == NULL) { 1015 if (body == NULL) {
1016 THROW_0(vmSymbols::java_lang_OutOfMemoryError()); 1016 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
1017 } 1017 }
1018 1018
1019 // caller responsible to free it: 1019 // caller responsible to free it:
1093 res_jh = JNIHandles::make_local(env, res_oop); 1093 res_jh = JNIHandles::make_local(env, res_oop);
1094 } 1094 }
1095 1095
1096 // try/finally clause: 1096 // try/finally clause:
1097 if (temp_alloc != NULL) { 1097 if (temp_alloc != NULL) {
1098 FREE_C_HEAP_ARRAY(HeapWord, temp_alloc); 1098 FREE_C_HEAP_ARRAY(HeapWord, temp_alloc, mtInternal);
1099 } 1099 }
1100 1100
1101 return (jclass) res_jh; 1101 return (jclass) res_jh;
1102 } 1102 }
1103 UNSAFE_END 1103 UNSAFE_END