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