1519 if (vf->is_compiled_frame()) {
1520 // compiled method frame
1521 compiledVFrame* cvf = compiledVFrame::cast(vf);
1522
1523 ScopeDesc* scope = cvf->scope();
1524 // native wrappers do not have a scope
1525 if (scope != nullptr && scope->objects() != nullptr) {
1526 prev_cvf = cvf;
1527
1528 GrowableArray<ScopeValue*>* objects = nullptr;
1529 if (!realloc_called) {
1530 objects = scope->objects();
1531 } else {
1532 // some object might already have been re-allocated, only reallocate the non-allocated ones
1533 objects = get_unallocated_objects_or_null(scope->objects());
1534 }
1535
1536 if (objects != nullptr) {
1537 RegisterMap reg_map(vf->register_map());
1538 bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), ®_map, objects, CHECK_NULL);
1539 Deoptimization::reassign_fields(vf->frame_pointer(), ®_map, objects, realloc_failures, false);
1540 realloc_called = true;
1541 }
1542
1543 GrowableArray<ScopeValue*>* local_values = scope->locals();
1544 for (int i = 0; i < local_values->length(); i++) {
1545 ScopeValue* value = local_values->at(i);
1546 assert(!value->is_object_merge(), "Should not be.");
1547 if (value->is_object()) {
1548 if (localIsVirtual_h.is_null()) {
1549 typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1550 localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1551 }
1552 localIsVirtual_h->bool_at_put(i, true);
1553 }
1554 }
1555 }
1556
1557 locals = cvf->locals();
1558 frame_number = cvf->vframe_id();
1559 } else {
1776 break;
1777 }
1778 vf = vf->sender();
1779 }
1780
1781 int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1782 if (last_frame_number >= virtualFrames->length()) {
1783 JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1784 }
1785
1786 // Reallocate the non-escaping objects and restore their fields.
1787 assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1788 GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1789
1790 if (objects == nullptr) {
1791 // no objects to materialize
1792 return;
1793 }
1794
1795 bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1796 Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1797
1798 for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1799 compiledVFrame* cvf = virtualFrames->at(frame_index);
1800
1801 GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1802 StackValueCollection* locals = cvf->locals();
1803 if (locals != nullptr) {
1804 for (int i2 = 0; i2 < locals->size(); i2++) {
1805 StackValue* var = locals->at(i2);
1806 assert(!scopedValues->at(i2)->is_object_merge(), "Should not be.");
1807 if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1808 jvalue val;
1809 val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1810 cvf->update_local(T_OBJECT, i2, val);
1811 }
1812 }
1813 }
1814
1815 GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1816 StackValueCollection* expressions = cvf->expressions();
2104 box_signature, &jargs, CHECK_NULL);
2105 oop hotspot_box = box_result.get_oop();
2106 JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2107 return JVMCIENV->get_jobject(result);
2108 C2V_END
2109
2110 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2111 Klass* klass = UNPACK_PAIR(Klass, klass);
2112 if (klass == nullptr) {
2113 JVMCI_THROW_0(NullPointerException);
2114 }
2115 if (!klass->is_instance_klass()) {
2116 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2117 return JVMCIENV->get_jobjectArray(methods);
2118 }
2119
2120 InstanceKlass* iklass = InstanceKlass::cast(klass);
2121 GrowableArray<Method*> constructors_array;
2122 for (int i = 0; i < iklass->methods()->length(); i++) {
2123 Method* m = iklass->methods()->at(i);
2124 if (m->is_initializer() && !m->is_static()) {
2125 constructors_array.append(m);
2126 }
2127 }
2128 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2129 for (int i = 0; i < constructors_array.length(); i++) {
2130 methodHandle ctor(THREAD, constructors_array.at(i));
2131 JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2132 JVMCIENV->put_object_at(methods, i, method);
2133 }
2134 return JVMCIENV->get_jobjectArray(methods);
2135 C2V_END
2136
2137 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2138 Klass* klass = UNPACK_PAIR(Klass, klass);
2139 if (klass == nullptr) {
2140 JVMCI_THROW_0(NullPointerException);
2141 }
2142 if (!klass->is_instance_klass()) {
2143 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2144 return JVMCIENV->get_jobjectArray(methods);
2145 }
2146
2147 InstanceKlass* iklass = InstanceKlass::cast(klass);
2148 GrowableArray<Method*> methods_array;
2149 for (int i = 0; i < iklass->methods()->length(); i++) {
2150 Method* m = iklass->methods()->at(i);
2151 if (!m->is_initializer() && !m->is_overpass()) {
2152 methods_array.append(m);
2153 }
2154 }
2155 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2156 for (int i = 0; i < methods_array.length(); i++) {
2157 methodHandle mh(THREAD, methods_array.at(i));
2158 JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2159 JVMCIENV->put_object_at(methods, i, method);
2160 }
2161 return JVMCIENV->get_jobjectArray(methods);
2162 C2V_END
2163
2164 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2165 Klass* klass = UNPACK_PAIR(Klass, klass);
2166 if (klass == nullptr) {
2167 JVMCI_THROW_0(NullPointerException);
2168 }
2169 if (!klass->is_instance_klass()) {
2170 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass");
2171 }
2844 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2845 JVMCIObject code = JVMCIENV->wrap(code_handle);
2846 CodeBlob* cb = JVMCIENV->get_code_blob(code);
2847 if (cb == nullptr) {
2848 return nullptr;
2849 }
2850 // Make a resource copy of code before the allocation causes a safepoint
2851 int code_size = cb->code_size();
2852 jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2853 memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2854
2855 JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2856 JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2857 return JVMCIENV->get_jbyteArray(result);
2858 C2V_END
2859
2860 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2861 requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2862 methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2863 oop executable;
2864 if (m->is_initializer()) {
2865 if (m->is_static_initializer()) {
2866 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2867 "Cannot create java.lang.reflect.Method for class initializer");
2868 }
2869 executable = Reflection::new_constructor(m, CHECK_NULL);
2870 } else {
2871 executable = Reflection::new_method(m, false, CHECK_NULL);
2872 }
2873 return JNIHandles::make_local(THREAD, executable);
2874 C2V_END
2875
2876 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2877 if (!klass->is_instance_klass()) {
2878 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2879 err_msg("Expected non-primitive type, got %s", klass->external_name()));
2880 }
2881 InstanceKlass* iklass = InstanceKlass::cast(klass);
2882 if (index < 0 || index > iklass->total_fields_count()) {
2883 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2884 err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2885 }
2886 return iklass;
2887 }
2888
|
1519 if (vf->is_compiled_frame()) {
1520 // compiled method frame
1521 compiledVFrame* cvf = compiledVFrame::cast(vf);
1522
1523 ScopeDesc* scope = cvf->scope();
1524 // native wrappers do not have a scope
1525 if (scope != nullptr && scope->objects() != nullptr) {
1526 prev_cvf = cvf;
1527
1528 GrowableArray<ScopeValue*>* objects = nullptr;
1529 if (!realloc_called) {
1530 objects = scope->objects();
1531 } else {
1532 // some object might already have been re-allocated, only reallocate the non-allocated ones
1533 objects = get_unallocated_objects_or_null(scope->objects());
1534 }
1535
1536 if (objects != nullptr) {
1537 RegisterMap reg_map(vf->register_map());
1538 bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), ®_map, objects, CHECK_NULL);
1539 Deoptimization::reassign_fields(vf->frame_pointer(), ®_map, objects, realloc_failures, false, CHECK_NULL);
1540 realloc_called = true;
1541 }
1542
1543 GrowableArray<ScopeValue*>* local_values = scope->locals();
1544 for (int i = 0; i < local_values->length(); i++) {
1545 ScopeValue* value = local_values->at(i);
1546 assert(!value->is_object_merge(), "Should not be.");
1547 if (value->is_object()) {
1548 if (localIsVirtual_h.is_null()) {
1549 typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1550 localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1551 }
1552 localIsVirtual_h->bool_at_put(i, true);
1553 }
1554 }
1555 }
1556
1557 locals = cvf->locals();
1558 frame_number = cvf->vframe_id();
1559 } else {
1776 break;
1777 }
1778 vf = vf->sender();
1779 }
1780
1781 int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1782 if (last_frame_number >= virtualFrames->length()) {
1783 JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1784 }
1785
1786 // Reallocate the non-escaping objects and restore their fields.
1787 assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1788 GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1789
1790 if (objects == nullptr) {
1791 // no objects to materialize
1792 return;
1793 }
1794
1795 bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1796 Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false, THREAD);
1797
1798 for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1799 compiledVFrame* cvf = virtualFrames->at(frame_index);
1800
1801 GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1802 StackValueCollection* locals = cvf->locals();
1803 if (locals != nullptr) {
1804 for (int i2 = 0; i2 < locals->size(); i2++) {
1805 StackValue* var = locals->at(i2);
1806 assert(!scopedValues->at(i2)->is_object_merge(), "Should not be.");
1807 if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1808 jvalue val;
1809 val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1810 cvf->update_local(T_OBJECT, i2, val);
1811 }
1812 }
1813 }
1814
1815 GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1816 StackValueCollection* expressions = cvf->expressions();
2104 box_signature, &jargs, CHECK_NULL);
2105 oop hotspot_box = box_result.get_oop();
2106 JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2107 return JVMCIENV->get_jobject(result);
2108 C2V_END
2109
2110 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2111 Klass* klass = UNPACK_PAIR(Klass, klass);
2112 if (klass == nullptr) {
2113 JVMCI_THROW_0(NullPointerException);
2114 }
2115 if (!klass->is_instance_klass()) {
2116 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2117 return JVMCIENV->get_jobjectArray(methods);
2118 }
2119
2120 InstanceKlass* iklass = InstanceKlass::cast(klass);
2121 GrowableArray<Method*> constructors_array;
2122 for (int i = 0; i < iklass->methods()->length(); i++) {
2123 Method* m = iklass->methods()->at(i);
2124 if (m->is_object_constructor()) {
2125 constructors_array.append(m);
2126 }
2127 }
2128 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2129 for (int i = 0; i < constructors_array.length(); i++) {
2130 methodHandle ctor(THREAD, constructors_array.at(i));
2131 JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2132 JVMCIENV->put_object_at(methods, i, method);
2133 }
2134 return JVMCIENV->get_jobjectArray(methods);
2135 C2V_END
2136
2137 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2138 Klass* klass = UNPACK_PAIR(Klass, klass);
2139 if (klass == nullptr) {
2140 JVMCI_THROW_0(NullPointerException);
2141 }
2142 if (!klass->is_instance_klass()) {
2143 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2144 return JVMCIENV->get_jobjectArray(methods);
2145 }
2146
2147 InstanceKlass* iklass = InstanceKlass::cast(klass);
2148 GrowableArray<Method*> methods_array;
2149 for (int i = 0; i < iklass->methods()->length(); i++) {
2150 Method* m = iklass->methods()->at(i);
2151 if (!(m->is_object_constructor() || m->is_class_initializer()) && !m->is_overpass()) {
2152 methods_array.append(m);
2153 }
2154 }
2155 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2156 for (int i = 0; i < methods_array.length(); i++) {
2157 methodHandle mh(THREAD, methods_array.at(i));
2158 JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2159 JVMCIENV->put_object_at(methods, i, method);
2160 }
2161 return JVMCIENV->get_jobjectArray(methods);
2162 C2V_END
2163
2164 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2165 Klass* klass = UNPACK_PAIR(Klass, klass);
2166 if (klass == nullptr) {
2167 JVMCI_THROW_0(NullPointerException);
2168 }
2169 if (!klass->is_instance_klass()) {
2170 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass");
2171 }
2844 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2845 JVMCIObject code = JVMCIENV->wrap(code_handle);
2846 CodeBlob* cb = JVMCIENV->get_code_blob(code);
2847 if (cb == nullptr) {
2848 return nullptr;
2849 }
2850 // Make a resource copy of code before the allocation causes a safepoint
2851 int code_size = cb->code_size();
2852 jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2853 memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2854
2855 JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2856 JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2857 return JVMCIENV->get_jbyteArray(result);
2858 C2V_END
2859
2860 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2861 requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2862 methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2863 oop executable;
2864 if (m->is_class_initializer()) {
2865 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2866 "Cannot create java.lang.reflect.Method for class initializer");
2867 }
2868 else if (m->is_object_constructor()) {
2869 executable = Reflection::new_constructor(m, CHECK_NULL);
2870 } else {
2871 executable = Reflection::new_method(m, false, CHECK_NULL);
2872 }
2873 return JNIHandles::make_local(THREAD, executable);
2874 C2V_END
2875
2876 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2877 if (!klass->is_instance_klass()) {
2878 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2879 err_msg("Expected non-primitive type, got %s", klass->external_name()));
2880 }
2881 InstanceKlass* iklass = InstanceKlass::cast(klass);
2882 if (index < 0 || index > iklass->total_fields_count()) {
2883 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2884 err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2885 }
2886 return iklass;
2887 }
2888
|