1582 if (vf->is_compiled_frame()) {
1583 // compiled method frame
1584 compiledVFrame* cvf = compiledVFrame::cast(vf);
1585
1586 ScopeDesc* scope = cvf->scope();
1587 // native wrappers do not have a scope
1588 if (scope != nullptr && scope->objects() != nullptr) {
1589 prev_cvf = cvf;
1590
1591 GrowableArray<ScopeValue*>* objects = nullptr;
1592 if (!realloc_called) {
1593 objects = scope->objects();
1594 } else {
1595 // some object might already have been re-allocated, only reallocate the non-allocated ones
1596 objects = get_unallocated_objects_or_null(scope->objects());
1597 }
1598
1599 if (objects != nullptr) {
1600 RegisterMap reg_map(vf->register_map());
1601 bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), ®_map, objects, CHECK_NULL);
1602 Deoptimization::reassign_fields(vf->frame_pointer(), ®_map, objects, realloc_failures, false);
1603 realloc_called = true;
1604 }
1605
1606 GrowableArray<ScopeValue*>* local_values = scope->locals();
1607 for (int i = 0; i < local_values->length(); i++) {
1608 ScopeValue* value = local_values->at(i);
1609 assert(!value->is_object_merge(), "Should not be.");
1610 if (value->is_object()) {
1611 if (localIsVirtual_h.is_null()) {
1612 typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1613 localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1614 }
1615 localIsVirtual_h->bool_at_put(i, true);
1616 }
1617 }
1618 }
1619
1620 locals = cvf->locals();
1621 frame_number = cvf->vframe_id();
1622 } else {
1833 break;
1834 }
1835 vf = vf->sender();
1836 }
1837
1838 int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1839 if (last_frame_number >= virtualFrames->length()) {
1840 JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1841 }
1842
1843 // Reallocate the non-escaping objects and restore their fields.
1844 assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1845 GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1846
1847 if (objects == nullptr) {
1848 // no objects to materialize
1849 return;
1850 }
1851
1852 bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1853 Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1854
1855 for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1856 compiledVFrame* cvf = virtualFrames->at(frame_index);
1857
1858 GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1859 StackValueCollection* locals = cvf->locals();
1860 if (locals != nullptr) {
1861 for (int i2 = 0; i2 < locals->size(); i2++) {
1862 StackValue* var = locals->at(i2);
1863 assert(!scopedValues->at(i2)->is_object_merge(), "Should not be.");
1864 if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1865 jvalue val;
1866 val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1867 cvf->update_local(T_OBJECT, i2, val);
1868 }
1869 }
1870 }
1871
1872 GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1873 StackValueCollection* expressions = cvf->expressions();
2161 box_signature, &jargs, CHECK_NULL);
2162 oop hotspot_box = box_result.get_oop();
2163 JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2164 return JVMCIENV->get_jobject(result);
2165 C2V_END
2166
2167 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2168 Klass* klass = UNPACK_PAIR(Klass, klass);
2169 if (klass == nullptr) {
2170 JVMCI_THROW_NULL(NullPointerException);
2171 }
2172 if (!klass->is_instance_klass()) {
2173 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2174 return JVMCIENV->get_jobjectArray(methods);
2175 }
2176
2177 InstanceKlass* iklass = InstanceKlass::cast(klass);
2178 GrowableArray<Method*> constructors_array;
2179 for (int i = 0; i < iklass->methods()->length(); i++) {
2180 Method* m = iklass->methods()->at(i);
2181 if (m->is_object_initializer()) {
2182 constructors_array.append(m);
2183 }
2184 }
2185 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2186 for (int i = 0; i < constructors_array.length(); i++) {
2187 methodHandle ctor(THREAD, constructors_array.at(i));
2188 JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2189 JVMCIENV->put_object_at(methods, i, method);
2190 }
2191 return JVMCIENV->get_jobjectArray(methods);
2192 C2V_END
2193
2194 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2195 Klass* klass = UNPACK_PAIR(Klass, klass);
2196 if (klass == nullptr) {
2197 JVMCI_THROW_NULL(NullPointerException);
2198 }
2199 if (!klass->is_instance_klass()) {
2200 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2201 return JVMCIENV->get_jobjectArray(methods);
2202 }
2203
2204 InstanceKlass* iklass = InstanceKlass::cast(klass);
2205 GrowableArray<Method*> methods_array;
2206 for (int i = 0; i < iklass->methods()->length(); i++) {
2207 Method* m = iklass->methods()->at(i);
2208 if (!m->is_object_initializer() && !m->is_static_initializer() && !m->is_overpass()) {
2209 methods_array.append(m);
2210 }
2211 }
2212 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2213 for (int i = 0; i < methods_array.length(); i++) {
2214 methodHandle mh(THREAD, methods_array.at(i));
2215 JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2216 JVMCIENV->put_object_at(methods, i, method);
2217 }
2218 return JVMCIENV->get_jobjectArray(methods);
2219 C2V_END
2220
2221 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2222 Klass* klass = UNPACK_PAIR(Klass, klass);
2223 if (klass == nullptr) {
2224 JVMCI_THROW_NULL(NullPointerException);
2225 }
2226 if (!klass->is_instance_klass()) {
2227 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass");
2228 }
2904 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2905 JVMCIObject code = JVMCIENV->wrap(code_handle);
2906 CodeBlob* cb = JVMCIENV->get_code_blob(code);
2907 if (cb == nullptr) {
2908 return nullptr;
2909 }
2910 // Make a resource copy of code before the allocation causes a safepoint
2911 int code_size = cb->code_size();
2912 jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2913 memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2914
2915 JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2916 JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2917 return JVMCIENV->get_jbyteArray(result);
2918 C2V_END
2919
2920 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2921 requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2922 methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2923 oop executable;
2924 if (m->is_object_initializer()) {
2925 executable = Reflection::new_constructor(m, CHECK_NULL);
2926 } else if (m->is_static_initializer()) {
2927 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2928 "Cannot create java.lang.reflect.Method for class initializer");
2929 } else {
2930 executable = Reflection::new_method(m, false, CHECK_NULL);
2931 }
2932 return JNIHandles::make_local(THREAD, executable);
2933 C2V_END
2934
2935 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2936 if (!klass->is_instance_klass()) {
2937 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2938 err_msg("Expected non-primitive type, got %s", klass->external_name()));
2939 }
2940 InstanceKlass* iklass = InstanceKlass::cast(klass);
2941 if (index < 0 || index > iklass->total_fields_count()) {
2942 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2943 err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2944 }
2945 return iklass;
2946 }
2947
2948 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index))
|
1582 if (vf->is_compiled_frame()) {
1583 // compiled method frame
1584 compiledVFrame* cvf = compiledVFrame::cast(vf);
1585
1586 ScopeDesc* scope = cvf->scope();
1587 // native wrappers do not have a scope
1588 if (scope != nullptr && scope->objects() != nullptr) {
1589 prev_cvf = cvf;
1590
1591 GrowableArray<ScopeValue*>* objects = nullptr;
1592 if (!realloc_called) {
1593 objects = scope->objects();
1594 } else {
1595 // some object might already have been re-allocated, only reallocate the non-allocated ones
1596 objects = get_unallocated_objects_or_null(scope->objects());
1597 }
1598
1599 if (objects != nullptr) {
1600 RegisterMap reg_map(vf->register_map());
1601 bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), ®_map, objects, CHECK_NULL);
1602 Deoptimization::reassign_fields(vf->frame_pointer(), ®_map, objects, realloc_failures, false, CHECK_NULL);
1603 realloc_called = true;
1604 }
1605
1606 GrowableArray<ScopeValue*>* local_values = scope->locals();
1607 for (int i = 0; i < local_values->length(); i++) {
1608 ScopeValue* value = local_values->at(i);
1609 assert(!value->is_object_merge(), "Should not be.");
1610 if (value->is_object()) {
1611 if (localIsVirtual_h.is_null()) {
1612 typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1613 localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1614 }
1615 localIsVirtual_h->bool_at_put(i, true);
1616 }
1617 }
1618 }
1619
1620 locals = cvf->locals();
1621 frame_number = cvf->vframe_id();
1622 } else {
1833 break;
1834 }
1835 vf = vf->sender();
1836 }
1837
1838 int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1839 if (last_frame_number >= virtualFrames->length()) {
1840 JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1841 }
1842
1843 // Reallocate the non-escaping objects and restore their fields.
1844 assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1845 GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1846
1847 if (objects == nullptr) {
1848 // no objects to materialize
1849 return;
1850 }
1851
1852 bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1853 Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false, THREAD);
1854
1855 for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1856 compiledVFrame* cvf = virtualFrames->at(frame_index);
1857
1858 GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1859 StackValueCollection* locals = cvf->locals();
1860 if (locals != nullptr) {
1861 for (int i2 = 0; i2 < locals->size(); i2++) {
1862 StackValue* var = locals->at(i2);
1863 assert(!scopedValues->at(i2)->is_object_merge(), "Should not be.");
1864 if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1865 jvalue val;
1866 val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1867 cvf->update_local(T_OBJECT, i2, val);
1868 }
1869 }
1870 }
1871
1872 GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1873 StackValueCollection* expressions = cvf->expressions();
2161 box_signature, &jargs, CHECK_NULL);
2162 oop hotspot_box = box_result.get_oop();
2163 JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2164 return JVMCIENV->get_jobject(result);
2165 C2V_END
2166
2167 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2168 Klass* klass = UNPACK_PAIR(Klass, klass);
2169 if (klass == nullptr) {
2170 JVMCI_THROW_NULL(NullPointerException);
2171 }
2172 if (!klass->is_instance_klass()) {
2173 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2174 return JVMCIENV->get_jobjectArray(methods);
2175 }
2176
2177 InstanceKlass* iklass = InstanceKlass::cast(klass);
2178 GrowableArray<Method*> constructors_array;
2179 for (int i = 0; i < iklass->methods()->length(); i++) {
2180 Method* m = iklass->methods()->at(i);
2181 if (m->is_object_constructor()) {
2182 constructors_array.append(m);
2183 }
2184 }
2185 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2186 for (int i = 0; i < constructors_array.length(); i++) {
2187 methodHandle ctor(THREAD, constructors_array.at(i));
2188 JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2189 JVMCIENV->put_object_at(methods, i, method);
2190 }
2191 return JVMCIENV->get_jobjectArray(methods);
2192 C2V_END
2193
2194 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2195 Klass* klass = UNPACK_PAIR(Klass, klass);
2196 if (klass == nullptr) {
2197 JVMCI_THROW_NULL(NullPointerException);
2198 }
2199 if (!klass->is_instance_klass()) {
2200 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2201 return JVMCIENV->get_jobjectArray(methods);
2202 }
2203
2204 InstanceKlass* iklass = InstanceKlass::cast(klass);
2205 GrowableArray<Method*> methods_array;
2206 for (int i = 0; i < iklass->methods()->length(); i++) {
2207 Method* m = iklass->methods()->at(i);
2208 if (!(m->is_object_constructor() || m->is_class_initializer()) && !m->is_overpass()) {
2209 methods_array.append(m);
2210 }
2211 }
2212 JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2213 for (int i = 0; i < methods_array.length(); i++) {
2214 methodHandle mh(THREAD, methods_array.at(i));
2215 JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2216 JVMCIENV->put_object_at(methods, i, method);
2217 }
2218 return JVMCIENV->get_jobjectArray(methods);
2219 C2V_END
2220
2221 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2222 Klass* klass = UNPACK_PAIR(Klass, klass);
2223 if (klass == nullptr) {
2224 JVMCI_THROW_NULL(NullPointerException);
2225 }
2226 if (!klass->is_instance_klass()) {
2227 JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass");
2228 }
2904 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2905 JVMCIObject code = JVMCIENV->wrap(code_handle);
2906 CodeBlob* cb = JVMCIENV->get_code_blob(code);
2907 if (cb == nullptr) {
2908 return nullptr;
2909 }
2910 // Make a resource copy of code before the allocation causes a safepoint
2911 int code_size = cb->code_size();
2912 jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2913 memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2914
2915 JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2916 JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2917 return JVMCIENV->get_jbyteArray(result);
2918 C2V_END
2919
2920 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2921 requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2922 methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2923 oop executable;
2924 if (m->is_class_initializer()) {
2925 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2926 "Cannot create java.lang.reflect.Method for class initializer");
2927 }
2928 else if (m->is_object_constructor()) {
2929 executable = Reflection::new_constructor(m, CHECK_NULL);
2930 } else {
2931 executable = Reflection::new_method(m, false, CHECK_NULL);
2932 }
2933 return JNIHandles::make_local(THREAD, executable);
2934 C2V_END
2935
2936 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2937 if (!klass->is_instance_klass()) {
2938 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2939 err_msg("Expected non-primitive type, got %s", klass->external_name()));
2940 }
2941 InstanceKlass* iklass = InstanceKlass::cast(klass);
2942 if (index < 0 || index > iklass->total_fields_count()) {
2943 JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2944 err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2945 }
2946 return iklass;
2947 }
2948
2949 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index))
|