Mercurial > hg > truffle
comparison src/share/vm/prims/jni.cpp @ 6275:957c266d8bc5
Merge with http://hg.openjdk.java.net/hsx/hsx24/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 21 Aug 2012 10:39:19 +0200 |
parents | 120820e30baa d2a62e0f25eb |
children | e522a00b91aa |
comparison
equal
deleted
inserted
replaced
5891:fd8832ae511d | 6275:957c266d8bc5 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
21 * questions. | 21 * questions. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 #include "classfile/altHashing.hpp" | |
26 #include "classfile/classLoader.hpp" | 27 #include "classfile/classLoader.hpp" |
27 #include "classfile/javaClasses.hpp" | 28 #include "classfile/javaClasses.hpp" |
28 #include "classfile/symbolTable.hpp" | 29 #include "classfile/symbolTable.hpp" |
29 #include "classfile/systemDictionary.hpp" | 30 #include "classfile/systemDictionary.hpp" |
30 #include "classfile/vmSymbols.hpp" | 31 #include "classfile/vmSymbols.hpp" |
36 #include "graal/graalVMToInterpreter.hpp" | 37 #include "graal/graalVMToInterpreter.hpp" |
37 #endif | 38 #endif |
38 #ifndef SERIALGC | 39 #ifndef SERIALGC |
39 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" | 40 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
40 #endif // SERIALGC | 41 #endif // SERIALGC |
42 #include "memory/allocation.hpp" | |
41 #include "memory/allocation.inline.hpp" | 43 #include "memory/allocation.inline.hpp" |
42 #include "memory/gcLocker.inline.hpp" | 44 #include "memory/gcLocker.inline.hpp" |
43 #include "memory/oopFactory.hpp" | 45 #include "memory/oopFactory.hpp" |
44 #include "memory/universe.inline.hpp" | 46 #include "memory/universe.inline.hpp" |
45 #include "oops/instanceKlass.hpp" | 47 #include "oops/instanceKlass.hpp" |
382 env, (char*) name, loaderRef, (char*) buf, bufLen); | 384 env, (char*) name, loaderRef, (char*) buf, bufLen); |
383 #endif /* USDT2 */ | 385 #endif /* USDT2 */ |
384 jclass cls = NULL; | 386 jclass cls = NULL; |
385 DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls); | 387 DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls); |
386 | 388 |
389 TempNewSymbol class_name = NULL; | |
387 // Since exceptions can be thrown, class initialization can take place | 390 // Since exceptions can be thrown, class initialization can take place |
388 // if name is NULL no check for class name in .class stream has to be made. | 391 // if name is NULL no check for class name in .class stream has to be made. |
389 if (name != NULL) { | 392 if (name != NULL) { |
390 const int str_len = (int)strlen(name); | 393 const int str_len = (int)strlen(name); |
391 if (str_len > Symbol::max_length()) { | 394 if (str_len > Symbol::max_length()) { |
392 // It's impossible to create this class; the name cannot fit | 395 // It's impossible to create this class; the name cannot fit |
393 // into the constant pool. | 396 // into the constant pool. |
394 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); | 397 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); |
395 } | 398 } |
396 } | 399 class_name = SymbolTable::new_symbol(name, CHECK_NULL); |
397 TempNewSymbol class_name = SymbolTable::new_symbol(name, THREAD); | 400 } |
398 | |
399 ResourceMark rm(THREAD); | 401 ResourceMark rm(THREAD); |
400 ClassFileStream st((u1*) buf, bufLen, NULL); | 402 ClassFileStream st((u1*) buf, bufLen, NULL); |
401 Handle class_loader (THREAD, JNIHandles::resolve(loaderRef)); | 403 Handle class_loader (THREAD, JNIHandles::resolve(loaderRef)); |
402 | 404 |
403 if (UsePerfData && !class_loader.is_null()) { | 405 if (UsePerfData && !class_loader.is_null()) { |
3295 } | 3297 } |
3296 oop s = JNIHandles::resolve_non_null(string); | 3298 oop s = JNIHandles::resolve_non_null(string); |
3297 int s_len = java_lang_String::length(s); | 3299 int s_len = java_lang_String::length(s); |
3298 typeArrayOop s_value = java_lang_String::value(s); | 3300 typeArrayOop s_value = java_lang_String::value(s); |
3299 int s_offset = java_lang_String::offset(s); | 3301 int s_offset = java_lang_String::offset(s); |
3300 jchar* buf = NEW_C_HEAP_ARRAY(jchar, s_len + 1); // add one for zero termination | 3302 jchar* buf = NEW_C_HEAP_ARRAY(jchar, s_len + 1, mtInternal); // add one for zero termination |
3301 if (s_len > 0) { | 3303 if (s_len > 0) { |
3302 memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len); | 3304 memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len); |
3303 } | 3305 } |
3304 buf[s_len] = 0; | 3306 buf[s_len] = 0; |
3305 #ifndef USDT2 | 3307 #ifndef USDT2 |
3388 HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY( | 3390 HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY( |
3389 env, string, (uintptr_t *) isCopy); | 3391 env, string, (uintptr_t *) isCopy); |
3390 #endif /* USDT2 */ | 3392 #endif /* USDT2 */ |
3391 oop java_string = JNIHandles::resolve_non_null(string); | 3393 oop java_string = JNIHandles::resolve_non_null(string); |
3392 size_t length = java_lang_String::utf8_length(java_string); | 3394 size_t length = java_lang_String::utf8_length(java_string); |
3393 char* result = AllocateHeap(length + 1, "GetStringUTFChars"); | 3395 char* result = AllocateHeap(length + 1, mtInternal); |
3394 java_lang_String::as_utf8_string(java_string, result, (int) length + 1); | 3396 java_lang_String::as_utf8_string(java_string, result, (int) length + 1); |
3395 if (isCopy != NULL) *isCopy = JNI_TRUE; | 3397 if (isCopy != NULL) *isCopy = JNI_TRUE; |
3396 #ifndef USDT2 | 3398 #ifndef USDT2 |
3397 DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result); | 3399 DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result); |
3398 #else /* USDT2 */ | 3400 #else /* USDT2 */ |
3644 /* Empty array: legal but useless, can't return NULL. \ | 3646 /* Empty array: legal but useless, can't return NULL. \ |
3645 * Return a pointer to something useless. \ | 3647 * Return a pointer to something useless. \ |
3646 * Avoid asserts in typeArrayOop. */ \ | 3648 * Avoid asserts in typeArrayOop. */ \ |
3647 result = (ElementType*)get_bad_address(); \ | 3649 result = (ElementType*)get_bad_address(); \ |
3648 } else { \ | 3650 } else { \ |
3649 result = NEW_C_HEAP_ARRAY(ElementType, len); \ | 3651 result = NEW_C_HEAP_ARRAY(ElementType, len, mtInternal); \ |
3650 /* copy the array to the c chunk */ \ | 3652 /* copy the array to the c chunk */ \ |
3651 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ | 3653 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ |
3652 } \ | 3654 } \ |
3653 if (isCopy) *isCopy = JNI_TRUE; \ | 3655 if (isCopy) *isCopy = JNI_TRUE; \ |
3654 DTRACE_PROBE1(hotspot_jni, Get##Result##ArrayElements__return, result);\ | 3656 DTRACE_PROBE1(hotspot_jni, Get##Result##ArrayElements__return, result);\ |
3681 /* Empty array: legal but useless, can't return NULL. \ | 3683 /* Empty array: legal but useless, can't return NULL. \ |
3682 * Return a pointer to something useless. \ | 3684 * Return a pointer to something useless. \ |
3683 * Avoid asserts in typeArrayOop. */ \ | 3685 * Avoid asserts in typeArrayOop. */ \ |
3684 result = (ElementType*)get_bad_address(); \ | 3686 result = (ElementType*)get_bad_address(); \ |
3685 } else { \ | 3687 } else { \ |
3686 result = NEW_C_HEAP_ARRAY(ElementType, len); \ | 3688 result = NEW_C_HEAP_ARRAY(ElementType, len, mtInternal); \ |
3687 /* copy the array to the c chunk */ \ | 3689 /* copy the array to the c chunk */ \ |
3688 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ | 3690 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ |
3689 } \ | 3691 } \ |
3690 if (isCopy) *isCopy = JNI_TRUE; \ | 3692 if (isCopy) *isCopy = JNI_TRUE; \ |
3691 ReturnProbe; \ | 3693 ReturnProbe; \ |
5079 if (ExecuteInternalVMTests) { | 5081 if (ExecuteInternalVMTests) { |
5080 tty->print_cr("Running internal VM tests"); | 5082 tty->print_cr("Running internal VM tests"); |
5081 run_unit_test(arrayOopDesc::test_max_array_length()); | 5083 run_unit_test(arrayOopDesc::test_max_array_length()); |
5082 run_unit_test(CollectedHeap::test_is_in()); | 5084 run_unit_test(CollectedHeap::test_is_in()); |
5083 run_unit_test(QuickSort::test_quick_sort()); | 5085 run_unit_test(QuickSort::test_quick_sort()); |
5086 run_unit_test(AltHashing::test_alt_hash()); | |
5084 tty->print_cr("All internal VM tests passed"); | 5087 tty->print_cr("All internal VM tests passed"); |
5085 } | 5088 } |
5086 } | 5089 } |
5087 | 5090 |
5088 #undef run_unit_test | 5091 #undef run_unit_test |