comparison src/share/vm/prims/jni.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 e9140bf80b4a
children 957c266d8bc5 da91efe96a93
comparison
equal deleted inserted replaced
6174:74533f63b116 6197:d2a62e0f25eb
31 #include "classfile/vmSymbols.hpp" 31 #include "classfile/vmSymbols.hpp"
32 #include "interpreter/linkResolver.hpp" 32 #include "interpreter/linkResolver.hpp"
33 #ifndef SERIALGC 33 #ifndef SERIALGC
34 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" 34 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
35 #endif // SERIALGC 35 #endif // SERIALGC
36 #include "memory/allocation.hpp"
36 #include "memory/allocation.inline.hpp" 37 #include "memory/allocation.inline.hpp"
37 #include "memory/gcLocker.inline.hpp" 38 #include "memory/gcLocker.inline.hpp"
38 #include "memory/oopFactory.hpp" 39 #include "memory/oopFactory.hpp"
39 #include "memory/universe.inline.hpp" 40 #include "memory/universe.inline.hpp"
40 #include "oops/instanceKlass.hpp" 41 #include "oops/instanceKlass.hpp"
3268 } 3269 }
3269 oop s = JNIHandles::resolve_non_null(string); 3270 oop s = JNIHandles::resolve_non_null(string);
3270 int s_len = java_lang_String::length(s); 3271 int s_len = java_lang_String::length(s);
3271 typeArrayOop s_value = java_lang_String::value(s); 3272 typeArrayOop s_value = java_lang_String::value(s);
3272 int s_offset = java_lang_String::offset(s); 3273 int s_offset = java_lang_String::offset(s);
3273 jchar* buf = NEW_C_HEAP_ARRAY(jchar, s_len + 1); // add one for zero termination 3274 jchar* buf = NEW_C_HEAP_ARRAY(jchar, s_len + 1, mtInternal); // add one for zero termination
3274 if (s_len > 0) { 3275 if (s_len > 0) {
3275 memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len); 3276 memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len);
3276 } 3277 }
3277 buf[s_len] = 0; 3278 buf[s_len] = 0;
3278 #ifndef USDT2 3279 #ifndef USDT2
3361 HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY( 3362 HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY(
3362 env, string, (uintptr_t *) isCopy); 3363 env, string, (uintptr_t *) isCopy);
3363 #endif /* USDT2 */ 3364 #endif /* USDT2 */
3364 oop java_string = JNIHandles::resolve_non_null(string); 3365 oop java_string = JNIHandles::resolve_non_null(string);
3365 size_t length = java_lang_String::utf8_length(java_string); 3366 size_t length = java_lang_String::utf8_length(java_string);
3366 char* result = AllocateHeap(length + 1, "GetStringUTFChars"); 3367 char* result = AllocateHeap(length + 1, mtInternal);
3367 java_lang_String::as_utf8_string(java_string, result, (int) length + 1); 3368 java_lang_String::as_utf8_string(java_string, result, (int) length + 1);
3368 if (isCopy != NULL) *isCopy = JNI_TRUE; 3369 if (isCopy != NULL) *isCopy = JNI_TRUE;
3369 #ifndef USDT2 3370 #ifndef USDT2
3370 DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result); 3371 DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result);
3371 #else /* USDT2 */ 3372 #else /* USDT2 */
3617 /* Empty array: legal but useless, can't return NULL. \ 3618 /* Empty array: legal but useless, can't return NULL. \
3618 * Return a pointer to something useless. \ 3619 * Return a pointer to something useless. \
3619 * Avoid asserts in typeArrayOop. */ \ 3620 * Avoid asserts in typeArrayOop. */ \
3620 result = (ElementType*)get_bad_address(); \ 3621 result = (ElementType*)get_bad_address(); \
3621 } else { \ 3622 } else { \
3622 result = NEW_C_HEAP_ARRAY(ElementType, len); \ 3623 result = NEW_C_HEAP_ARRAY(ElementType, len, mtInternal); \
3623 /* copy the array to the c chunk */ \ 3624 /* copy the array to the c chunk */ \
3624 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ 3625 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \
3625 } \ 3626 } \
3626 if (isCopy) *isCopy = JNI_TRUE; \ 3627 if (isCopy) *isCopy = JNI_TRUE; \
3627 DTRACE_PROBE1(hotspot_jni, Get##Result##ArrayElements__return, result);\ 3628 DTRACE_PROBE1(hotspot_jni, Get##Result##ArrayElements__return, result);\
3654 /* Empty array: legal but useless, can't return NULL. \ 3655 /* Empty array: legal but useless, can't return NULL. \
3655 * Return a pointer to something useless. \ 3656 * Return a pointer to something useless. \
3656 * Avoid asserts in typeArrayOop. */ \ 3657 * Avoid asserts in typeArrayOop. */ \
3657 result = (ElementType*)get_bad_address(); \ 3658 result = (ElementType*)get_bad_address(); \
3658 } else { \ 3659 } else { \
3659 result = NEW_C_HEAP_ARRAY(ElementType, len); \ 3660 result = NEW_C_HEAP_ARRAY(ElementType, len, mtInternal); \
3660 /* copy the array to the c chunk */ \ 3661 /* copy the array to the c chunk */ \
3661 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ 3662 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \
3662 } \ 3663 } \
3663 if (isCopy) *isCopy = JNI_TRUE; \ 3664 if (isCopy) *isCopy = JNI_TRUE; \
3664 ReturnProbe; \ 3665 ReturnProbe; \