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