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