15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "code/nmethod.hpp"
29 #include "compiler/compileBroker.hpp"
30 #include "interpreter/interpreter.hpp"
31 #include "interpreter/linkResolver.hpp"
32 #include "memory/universe.hpp"
33 #include "oops/method.inline.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "prims/jniCheck.hpp"
36 #include "runtime/compilationPolicy.hpp"
37 #include "runtime/handles.inline.hpp"
38 #include "runtime/interfaceSupport.inline.hpp"
39 #include "runtime/javaCalls.hpp"
40 #include "runtime/jniHandles.inline.hpp"
41 #include "runtime/mutexLocker.hpp"
42 #include "runtime/os.inline.hpp"
43 #include "runtime/sharedRuntime.hpp"
44 #include "runtime/signature.hpp"
45 #include "runtime/stubRoutines.hpp"
46 #include "runtime/thread.inline.hpp"
47 #if INCLUDE_JVMCI
48 #include "jvmci/jvmciJavaClasses.hpp"
49 #include "jvmci/jvmciRuntime.hpp"
50 #endif
51
52 // -----------------------------------------------------
53 // Implementation of JavaCallWrapper
54
141 // on sparc/ia64 which will catch violations of the reseting of last_Java_frame
142 // invariants (i.e. _flags always cleared on return to Java)
143
144 _thread->frame_anchor()->copy(&_anchor);
145
146 // Release handles after we are marked as being inside the VM again, since this
147 // operation might block
148 JNIHandleBlock::release_block(_old_handles, _thread);
149 }
150
151
152 void JavaCallWrapper::oops_do(OopClosure* f) {
153 f->do_oop((oop*)&_receiver);
154 handles()->oops_do(f);
155 }
156
157
158 // Helper methods
159 static BasicType runtime_type_from(JavaValue* result) {
160 switch (result->get_type()) {
161 case T_BOOLEAN: // fall through
162 case T_CHAR : // fall through
163 case T_SHORT : // fall through
164 case T_INT : // fall through
165 #ifndef _LP64
166 case T_OBJECT : // fall through
167 case T_ARRAY : // fall through
168 #endif
169 case T_BYTE : // fall through
170 case T_VOID : return T_INT;
171 case T_LONG : return T_LONG;
172 case T_FLOAT : return T_FLOAT;
173 case T_DOUBLE : return T_DOUBLE;
174 #ifdef _LP64
175 case T_ARRAY : // fall through
176 case T_OBJECT: return T_OBJECT;
177 #endif
178 default:
179 ShouldNotReachHere();
180 return T_ILLEGAL;
181 }
182 }
183
184 // ============ Virtual calls ============
185
186 void JavaCalls::call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
187 CallInfo callinfo;
188 Handle receiver = args->receiver();
189 Klass* recvrKlass = receiver.is_null() ? (Klass*)NULL : receiver->klass();
190 LinkInfo link_info(spec_klass, name, signature);
191 LinkResolver::resolve_virtual_call(
192 callinfo, receiver, recvrKlass, link_info, true, CHECK);
193 methodHandle method = callinfo.selected_method();
194 assert(method.not_null(), "should have thrown exception");
195
196 // Invoke the method
380 // A klass might not be initialized since JavaCall's might be used during the executing of
381 // the <clinit>. For example, a Thread.start might start executing on an object that is
382 // not fully initialized! (bad Java programming style)
383 assert(holder->is_linked(), "rewriting must have taken place");
384 }
385 #endif
386
387 CompilationPolicy::compile_if_required(method, CHECK);
388
389 // Since the call stub sets up like the interpreter we call the from_interpreted_entry
390 // so we can go compiled via a i2c. Otherwise initial entry method will always
391 // run interpreted.
392 address entry_point = method->from_interpreted_entry();
393 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
394 entry_point = method->interpreter_entry();
395 }
396
397 // Figure out if the result value is an oop or not (Note: This is a different value
398 // than result_type. result_type will be T_INT of oops. (it is about size)
399 BasicType result_type = runtime_type_from(result);
400 bool oop_result_flag = (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY);
401
402 // NOTE: if we move the computation of the result_val_address inside
403 // the call to call_stub, the optimizer produces wrong code.
404 intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
405
406 // Find receiver
407 Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
408
409 // When we reenter Java, we need to reenable the reserved/yellow zone which
410 // might already be disabled when we are in VM.
411 if (!thread->stack_guards_enabled()) {
412 thread->reguard_stack();
413 }
414
415 // Check that there are shadow pages available before changing thread state
416 // to Java. Calculate current_stack_pointer here to make sure
417 // stack_shadow_pages_available() and bang_stack_shadow_pages() use the same sp.
418 address sp = os::current_stack_pointer();
419 if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
420 // Throw stack overflow exception with preinitialized exception.
600 // Verify the pointee.
601 oop vv = resolve_indirect_oop(v, _value_state[_pos]);
602 guarantee(oopDesc::is_oop_or_null(vv, true),
603 "Bad JNI oop argument %d: " PTR_FORMAT " -> " PTR_FORMAT,
604 _pos, v, p2i(vv));
605 }
606
607 check_value(true); // Verify value state.
608 }
609
610 void do_bool() { check_int(T_BOOLEAN); }
611 void do_char() { check_int(T_CHAR); }
612 void do_float() { check_int(T_FLOAT); }
613 void do_double() { check_double(T_DOUBLE); }
614 void do_byte() { check_int(T_BYTE); }
615 void do_short() { check_int(T_SHORT); }
616 void do_int() { check_int(T_INT); }
617 void do_long() { check_long(T_LONG); }
618 void do_void() { check_return_type(T_VOID); }
619 void do_object(int begin, int end) { check_obj(T_OBJECT); }
620 void do_array(int begin, int end) { check_obj(T_OBJECT); }
621 };
622
623
624 void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
625 guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
626
627 // Treat T_OBJECT and T_ARRAY as the same
628 if (return_type == T_ARRAY) return_type = T_OBJECT;
629
630 // Check that oop information is correct
631 Symbol* signature = method->signature();
632
633 SignatureChekker sc(signature,
634 return_type,
635 method->is_static(),
636 _value_state,
637 _value);
638 sc.iterate_parameters();
639 sc.check_doing_return(true);
|
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "code/nmethod.hpp"
29 #include "compiler/compileBroker.hpp"
30 #include "interpreter/interpreter.hpp"
31 #include "interpreter/linkResolver.hpp"
32 #include "memory/universe.hpp"
33 #include "oops/method.inline.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "oops/valueKlass.hpp"
36 #include "prims/jniCheck.hpp"
37 #include "runtime/compilationPolicy.hpp"
38 #include "runtime/handles.inline.hpp"
39 #include "runtime/interfaceSupport.inline.hpp"
40 #include "runtime/javaCalls.hpp"
41 #include "runtime/jniHandles.inline.hpp"
42 #include "runtime/mutexLocker.hpp"
43 #include "runtime/os.inline.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/signature.hpp"
46 #include "runtime/stubRoutines.hpp"
47 #include "runtime/thread.inline.hpp"
48 #if INCLUDE_JVMCI
49 #include "jvmci/jvmciJavaClasses.hpp"
50 #include "jvmci/jvmciRuntime.hpp"
51 #endif
52
53 // -----------------------------------------------------
54 // Implementation of JavaCallWrapper
55
142 // on sparc/ia64 which will catch violations of the reseting of last_Java_frame
143 // invariants (i.e. _flags always cleared on return to Java)
144
145 _thread->frame_anchor()->copy(&_anchor);
146
147 // Release handles after we are marked as being inside the VM again, since this
148 // operation might block
149 JNIHandleBlock::release_block(_old_handles, _thread);
150 }
151
152
153 void JavaCallWrapper::oops_do(OopClosure* f) {
154 f->do_oop((oop*)&_receiver);
155 handles()->oops_do(f);
156 }
157
158
159 // Helper methods
160 static BasicType runtime_type_from(JavaValue* result) {
161 switch (result->get_type()) {
162 case T_BOOLEAN : // fall through
163 case T_CHAR : // fall through
164 case T_SHORT : // fall through
165 case T_INT : // fall through
166 #ifndef _LP64
167 case T_OBJECT : // fall through
168 case T_ARRAY : // fall through
169 case T_VALUETYPE: // fall through
170 #endif
171 case T_BYTE : // fall through
172 case T_VOID : return T_INT;
173 case T_LONG : return T_LONG;
174 case T_FLOAT : return T_FLOAT;
175 case T_DOUBLE : return T_DOUBLE;
176 #ifdef _LP64
177 case T_ARRAY : // fall through
178 case T_OBJECT : return T_OBJECT;
179 case T_VALUETYPE: return T_VALUETYPE;
180 #endif
181 default:
182 ShouldNotReachHere();
183 return T_ILLEGAL;
184 }
185 }
186
187 // ============ Virtual calls ============
188
189 void JavaCalls::call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
190 CallInfo callinfo;
191 Handle receiver = args->receiver();
192 Klass* recvrKlass = receiver.is_null() ? (Klass*)NULL : receiver->klass();
193 LinkInfo link_info(spec_klass, name, signature);
194 LinkResolver::resolve_virtual_call(
195 callinfo, receiver, recvrKlass, link_info, true, CHECK);
196 methodHandle method = callinfo.selected_method();
197 assert(method.not_null(), "should have thrown exception");
198
199 // Invoke the method
383 // A klass might not be initialized since JavaCall's might be used during the executing of
384 // the <clinit>. For example, a Thread.start might start executing on an object that is
385 // not fully initialized! (bad Java programming style)
386 assert(holder->is_linked(), "rewriting must have taken place");
387 }
388 #endif
389
390 CompilationPolicy::compile_if_required(method, CHECK);
391
392 // Since the call stub sets up like the interpreter we call the from_interpreted_entry
393 // so we can go compiled via a i2c. Otherwise initial entry method will always
394 // run interpreted.
395 address entry_point = method->from_interpreted_entry();
396 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
397 entry_point = method->interpreter_entry();
398 }
399
400 // Figure out if the result value is an oop or not (Note: This is a different value
401 // than result_type. result_type will be T_INT of oops. (it is about size)
402 BasicType result_type = runtime_type_from(result);
403 bool oop_result_flag = (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY
404 || result->get_type() == T_VALUETYPE);
405
406 // NOTE: if we move the computation of the result_val_address inside
407 // the call to call_stub, the optimizer produces wrong code.
408 intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
409
410 // Find receiver
411 Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
412
413 // When we reenter Java, we need to reenable the reserved/yellow zone which
414 // might already be disabled when we are in VM.
415 if (!thread->stack_guards_enabled()) {
416 thread->reguard_stack();
417 }
418
419 // Check that there are shadow pages available before changing thread state
420 // to Java. Calculate current_stack_pointer here to make sure
421 // stack_shadow_pages_available() and bang_stack_shadow_pages() use the same sp.
422 address sp = os::current_stack_pointer();
423 if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
424 // Throw stack overflow exception with preinitialized exception.
604 // Verify the pointee.
605 oop vv = resolve_indirect_oop(v, _value_state[_pos]);
606 guarantee(oopDesc::is_oop_or_null(vv, true),
607 "Bad JNI oop argument %d: " PTR_FORMAT " -> " PTR_FORMAT,
608 _pos, v, p2i(vv));
609 }
610
611 check_value(true); // Verify value state.
612 }
613
614 void do_bool() { check_int(T_BOOLEAN); }
615 void do_char() { check_int(T_CHAR); }
616 void do_float() { check_int(T_FLOAT); }
617 void do_double() { check_double(T_DOUBLE); }
618 void do_byte() { check_int(T_BYTE); }
619 void do_short() { check_int(T_SHORT); }
620 void do_int() { check_int(T_INT); }
621 void do_long() { check_long(T_LONG); }
622 void do_void() { check_return_type(T_VOID); }
623 void do_object(int begin, int end) { check_obj(T_OBJECT); }
624 void do_valuetype(int begin, int end){ check_obj(T_VALUETYPE); }
625 void do_array(int begin, int end) { check_obj(T_OBJECT); }
626 };
627
628
629 void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
630 guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
631
632 // Treat T_OBJECT and T_ARRAY as the same
633 if (return_type == T_ARRAY) return_type = T_OBJECT;
634
635 // Check that oop information is correct
636 Symbol* signature = method->signature();
637
638 SignatureChekker sc(signature,
639 return_type,
640 method->is_static(),
641 _value_state,
642 _value);
643 sc.iterate_parameters();
644 sc.check_doing_return(true);
|