annotate src/share/vm/runtime/javaCalls.cpp @ 5743:fc7177e457bf

Merge
author henryjen
date Mon, 11 Nov 2013 23:16:56 -0800
parents f34d701e952e
children
rev   line source
duke@0 1 /*
hseigel@5466 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1885 25 #include "precompiled.hpp"
stefank@1885 26 #include "classfile/systemDictionary.hpp"
stefank@1885 27 #include "classfile/vmSymbols.hpp"
stefank@1885 28 #include "code/nmethod.hpp"
stefank@1885 29 #include "compiler/compileBroker.hpp"
stefank@1885 30 #include "interpreter/interpreter.hpp"
stefank@1885 31 #include "interpreter/linkResolver.hpp"
stefank@1885 32 #include "memory/universe.inline.hpp"
stefank@1885 33 #include "oops/oop.inline.hpp"
stefank@1885 34 #include "prims/jniCheck.hpp"
stefank@1885 35 #include "runtime/compilationPolicy.hpp"
stefank@1885 36 #include "runtime/handles.inline.hpp"
stefank@1885 37 #include "runtime/interfaceSupport.hpp"
stefank@1885 38 #include "runtime/javaCalls.hpp"
stefank@1885 39 #include "runtime/mutexLocker.hpp"
stefank@1885 40 #include "runtime/signature.hpp"
stefank@1885 41 #include "runtime/stubRoutines.hpp"
stefank@3931 42 #include "runtime/thread.inline.hpp"
duke@0 43
duke@0 44 // -----------------------------------------------------
duke@0 45 // Implementation of JavaCallWrapper
duke@0 46
duke@0 47 JavaCallWrapper::JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS) {
duke@0 48 JavaThread* thread = (JavaThread *)THREAD;
duke@0 49 bool clear_pending_exception = true;
duke@0 50
duke@0 51 guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
duke@0 52 assert(!thread->owns_locks(), "must release all locks when leaving VM");
duke@0 53 guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
duke@0 54 _result = result;
duke@0 55
duke@0 56 // Allocate handle block for Java code. This must be done before we change thread_state to _thread_in_Java_or_stub,
duke@0 57 // since it can potentially block.
duke@0 58 JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread);
duke@0 59
duke@0 60 // After this, we are official in JavaCode. This needs to be done before we change any of the thread local
duke@0 61 // info, since we cannot find oops before the new information is set up completely.
duke@0 62 ThreadStateTransition::transition(thread, _thread_in_vm, _thread_in_Java);
duke@0 63
duke@0 64 // Make sure that we handle asynchronous stops and suspends _before_ we clear all thread state
duke@0 65 // in JavaCallWrapper::JavaCallWrapper(). This way, we can decide if we need to do any pd actions
duke@0 66 // to prepare for stop/suspend (flush register windows on sparcs, cache sp, or other state).
duke@0 67 if (thread->has_special_runtime_exit_condition()) {
duke@0 68 thread->handle_special_runtime_exit_condition();
duke@0 69 if (HAS_PENDING_EXCEPTION) {
duke@0 70 clear_pending_exception = false;
duke@0 71 }
duke@0 72 }
duke@0 73
duke@0 74
duke@0 75 // Make sure to set the oop's after the thread transition - since we can block there. No one is GC'ing
duke@0 76 // the JavaCallWrapper before the entry frame is on the stack.
duke@0 77 _callee_method = callee_method();
duke@0 78 _receiver = receiver();
duke@0 79
duke@0 80 #ifdef CHECK_UNHANDLED_OOPS
duke@0 81 THREAD->allow_unhandled_oop(&_receiver);
duke@0 82 #endif // CHECK_UNHANDLED_OOPS
duke@0 83
duke@0 84 _thread = (JavaThread *)thread;
duke@0 85 _handles = _thread->active_handles(); // save previous handle block & Java frame linkage
duke@0 86
duke@0 87 // For the profiler, the last_Java_frame information in thread must always be in
duke@0 88 // legal state. We have no last Java frame if last_Java_sp == NULL so
duke@0 89 // the valid transition is to clear _last_Java_sp and then reset the rest of
duke@0 90 // the (platform specific) state.
duke@0 91
duke@0 92 _anchor.copy(_thread->frame_anchor());
duke@0 93 _thread->frame_anchor()->clear();
duke@0 94
duke@0 95 debug_only(_thread->inc_java_call_counter());
duke@0 96 _thread->set_active_handles(new_handles); // install new handle block and reset Java frame linkage
duke@0 97
duke@0 98 assert (_thread->thread_state() != _thread_in_native, "cannot set native pc to NULL");
duke@0 99
duke@0 100 // clear any pending exception in thread (native calls start with no exception pending)
duke@0 101 if(clear_pending_exception) {
duke@0 102 _thread->clear_pending_exception();
duke@0 103 }
duke@0 104
duke@0 105 if (_anchor.last_Java_sp() == NULL) {
duke@0 106 _thread->record_base_of_stack_pointer();
duke@0 107 }
duke@0 108 }
duke@0 109
duke@0 110
duke@0 111 JavaCallWrapper::~JavaCallWrapper() {
duke@0 112 assert(_thread == JavaThread::current(), "must still be the same thread");
duke@0 113
duke@0 114 // restore previous handle block & Java frame linkage
duke@0 115 JNIHandleBlock *_old_handles = _thread->active_handles();
duke@0 116 _thread->set_active_handles(_handles);
duke@0 117
duke@0 118 _thread->frame_anchor()->zap();
duke@0 119
duke@0 120 debug_only(_thread->dec_java_call_counter());
duke@0 121
duke@0 122 if (_anchor.last_Java_sp() == NULL) {
duke@0 123 _thread->set_base_of_stack_pointer(NULL);
duke@0 124 }
duke@0 125
duke@0 126
duke@0 127 // Old thread-local info. has been restored. We are not back in the VM.
duke@0 128 ThreadStateTransition::transition_from_java(_thread, _thread_in_vm);
duke@0 129
duke@0 130 // State has been restored now make the anchor frame visible for the profiler.
duke@0 131 // Do this after the transition because this allows us to put an assert
duke@0 132 // the Java->vm transition which checks to see that stack is not walkable
duke@0 133 // on sparc/ia64 which will catch violations of the reseting of last_Java_frame
duke@0 134 // invariants (i.e. _flags always cleared on return to Java)
duke@0 135
duke@0 136 _thread->frame_anchor()->copy(&_anchor);
duke@0 137
duke@0 138 // Release handles after we are marked as being inside the VM again, since this
duke@0 139 // operation might block
duke@0 140 JNIHandleBlock::release_block(_old_handles, _thread);
duke@0 141 }
duke@0 142
duke@0 143
duke@0 144 void JavaCallWrapper::oops_do(OopClosure* f) {
duke@0 145 f->do_oop((oop*)&_receiver);
duke@0 146 handles()->oops_do(f);
duke@0 147 }
duke@0 148
duke@0 149
duke@0 150 // Helper methods
duke@0 151 static BasicType runtime_type_from(JavaValue* result) {
duke@0 152 switch (result->get_type()) {
duke@0 153 case T_BOOLEAN: // fall through
duke@0 154 case T_CHAR : // fall through
duke@0 155 case T_SHORT : // fall through
duke@0 156 case T_INT : // fall through
duke@0 157 #ifndef _LP64
duke@0 158 case T_OBJECT : // fall through
duke@0 159 case T_ARRAY : // fall through
duke@0 160 #endif
duke@0 161 case T_BYTE : // fall through
duke@0 162 case T_VOID : return T_INT;
duke@0 163 case T_LONG : return T_LONG;
duke@0 164 case T_FLOAT : return T_FLOAT;
duke@0 165 case T_DOUBLE : return T_DOUBLE;
duke@0 166 #ifdef _LP64
duke@0 167 case T_ARRAY : // fall through
duke@0 168 case T_OBJECT: return T_OBJECT;
duke@0 169 #endif
duke@0 170 }
duke@0 171 ShouldNotReachHere();
duke@0 172 return T_ILLEGAL;
duke@0 173 }
duke@0 174
duke@0 175 // ===== object constructor calls =====
duke@0 176
duke@0 177 void JavaCalls::call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS) {
duke@0 178 assert(method->name() == vmSymbols::object_initializer_name(), "Should only be called for default constructor");
duke@0 179 assert(method->signature() == vmSymbols::void_method_signature(), "Should only be called for default constructor");
duke@0 180
coleenp@3880 181 InstanceKlass* ik = method->method_holder();
duke@0 182 if (ik->is_initialized() && ik->has_vanilla_constructor()) {
duke@0 183 // safe to skip constructor call
duke@0 184 } else {
duke@0 185 static JavaValue result(T_VOID);
duke@0 186 JavaCallArguments args(receiver);
duke@0 187 call(&result, method, &args, CHECK);
duke@0 188 }
duke@0 189 }
duke@0 190
duke@0 191 // ============ Virtual calls ============
duke@0 192
coleenp@2069 193 void JavaCalls::call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
duke@0 194 CallInfo callinfo;
duke@0 195 Handle receiver = args->receiver();
coleenp@3656 196 KlassHandle recvrKlass(THREAD, receiver.is_null() ? (Klass*)NULL : receiver->klass());
duke@0 197 LinkResolver::resolve_virtual_call(
duke@0 198 callinfo, receiver, recvrKlass, spec_klass, name, signature,
duke@0 199 KlassHandle(), false, true, CHECK);
duke@0 200 methodHandle method = callinfo.selected_method();
duke@0 201 assert(method.not_null(), "should have thrown exception");
duke@0 202
duke@0 203 // Invoke the method
duke@0 204 JavaCalls::call(result, method, args, CHECK);
duke@0 205 }
duke@0 206
duke@0 207
coleenp@2069 208 void JavaCalls::call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS) {
duke@0 209 JavaCallArguments args(receiver); // One oop argument
duke@0 210 call_virtual(result, spec_klass, name, signature, &args, CHECK);
duke@0 211 }
duke@0 212
duke@0 213
coleenp@2069 214 void JavaCalls::call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
duke@0 215 JavaCallArguments args(receiver); // One oop argument
duke@0 216 args.push_oop(arg1);
duke@0 217 call_virtual(result, spec_klass, name, signature, &args, CHECK);
duke@0 218 }
duke@0 219
duke@0 220
duke@0 221
coleenp@2069 222 void JavaCalls::call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
duke@0 223 JavaCallArguments args(receiver); // One oop argument
duke@0 224 args.push_oop(arg1);
duke@0 225 args.push_oop(arg2);
duke@0 226 call_virtual(result, spec_klass, name, signature, &args, CHECK);
duke@0 227 }
duke@0 228
duke@0 229
duke@0 230 // ============ Special calls ============
duke@0 231
coleenp@2069 232 void JavaCalls::call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
duke@0 233 CallInfo callinfo;
duke@0 234 LinkResolver::resolve_special_call(callinfo, klass, name, signature, KlassHandle(), false, CHECK);
duke@0 235 methodHandle method = callinfo.selected_method();
duke@0 236 assert(method.not_null(), "should have thrown exception");
duke@0 237
duke@0 238 // Invoke the method
duke@0 239 JavaCalls::call(result, method, args, CHECK);
duke@0 240 }
duke@0 241
duke@0 242
coleenp@2069 243 void JavaCalls::call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
duke@0 244 JavaCallArguments args(receiver); // One oop argument
duke@0 245 call_special(result, klass, name, signature, &args, CHECK);
duke@0 246 }
duke@0 247
duke@0 248
coleenp@2069 249 void JavaCalls::call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
duke@0 250 JavaCallArguments args(receiver); // One oop argument
duke@0 251 args.push_oop(arg1);
duke@0 252 call_special(result, klass, name, signature, &args, CHECK);
duke@0 253 }
duke@0 254
duke@0 255
coleenp@2069 256 void JavaCalls::call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
duke@0 257 JavaCallArguments args(receiver); // One oop argument
duke@0 258 args.push_oop(arg1);
duke@0 259 args.push_oop(arg2);
duke@0 260 call_special(result, klass, name, signature, &args, CHECK);
duke@0 261 }
duke@0 262
duke@0 263
duke@0 264 // ============ Static calls ============
duke@0 265
coleenp@2069 266 void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
duke@0 267 CallInfo callinfo;
duke@0 268 LinkResolver::resolve_static_call(callinfo, klass, name, signature, KlassHandle(), false, true, CHECK);
duke@0 269 methodHandle method = callinfo.selected_method();
duke@0 270 assert(method.not_null(), "should have thrown exception");
duke@0 271
duke@0 272 // Invoke the method
duke@0 273 JavaCalls::call(result, method, args, CHECK);
duke@0 274 }
duke@0 275
duke@0 276
coleenp@2069 277 void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
duke@0 278 JavaCallArguments args; // No argument
duke@0 279 call_static(result, klass, name, signature, &args, CHECK);
duke@0 280 }
duke@0 281
duke@0 282
coleenp@2069 283 void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
duke@0 284 JavaCallArguments args(arg1); // One oop argument
duke@0 285 call_static(result, klass, name, signature, &args, CHECK);
duke@0 286 }
duke@0 287
duke@0 288
coleenp@2069 289 void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
duke@0 290 JavaCallArguments args; // One oop argument
duke@0 291 args.push_oop(arg1);
duke@0 292 args.push_oop(arg2);
duke@0 293 call_static(result, klass, name, signature, &args, CHECK);
duke@0 294 }
duke@0 295
duke@0 296
duke@0 297 // -------------------------------------------------
duke@0 298 // Implementation of JavaCalls (low level)
duke@0 299
duke@0 300
duke@0 301 void JavaCalls::call(JavaValue* result, methodHandle method, JavaCallArguments* args, TRAPS) {
duke@0 302 // Check if we need to wrap a potential OS exception handler around thread
duke@0 303 // This is used for e.g. Win32 structured exception handlers
duke@0 304 assert(THREAD->is_Java_thread(), "only JavaThreads can make JavaCalls");
duke@0 305 // Need to wrap each and everytime, since there might be native code down the
duke@0 306 // stack that has installed its own exception handlers
duke@0 307 os::os_exception_wrapper(call_helper, result, &method, args, THREAD);
duke@0 308 }
duke@0 309
duke@0 310 void JavaCalls::call_helper(JavaValue* result, methodHandle* m, JavaCallArguments* args, TRAPS) {
duke@0 311 methodHandle method = *m;
duke@0 312 JavaThread* thread = (JavaThread*)THREAD;
duke@0 313 assert(thread->is_Java_thread(), "must be called by a java thread");
duke@0 314 assert(method.not_null(), "must have a method to call");
duke@0 315 assert(!SafepointSynchronize::is_at_safepoint(), "call to Java code during VM operation");
duke@0 316 assert(!thread->handle_area()->no_handle_mark_active(), "cannot call out to Java here");
duke@0 317
duke@0 318
duke@0 319 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();)
duke@0 320
poonam@465 321 // Verify the arguments
poonam@465 322
poonam@465 323 if (CheckJNICalls) {
poonam@465 324 args->verify(method, result->get_type(), thread);
poonam@465 325 }
poonam@465 326 else debug_only(args->verify(method, result->get_type(), thread));
duke@0 327
duke@0 328 // Ignore call if method is empty
duke@0 329 if (method->is_empty_method()) {
duke@0 330 assert(result->get_type() == T_VOID, "an empty method must return a void value");
duke@0 331 return;
duke@0 332 }
duke@0 333
duke@0 334
duke@0 335 #ifdef ASSERT
coleenp@3880 336 { InstanceKlass* holder = method->method_holder();
duke@0 337 // A klass might not be initialized since JavaCall's might be used during the executing of
duke@0 338 // the <clinit>. For example, a Thread.start might start executing on an object that is
duke@0 339 // not fully initialized! (bad Java programming style)
coleenp@3880 340 assert(holder->is_linked(), "rewritting must have taken place");
duke@0 341 }
duke@0 342 #endif
duke@0 343
duke@0 344
duke@0 345 assert(!thread->is_Compiler_thread(), "cannot compile from the compiler");
iveresov@1707 346 if (CompilationPolicy::must_be_compiled(method)) {
duke@0 347 CompileBroker::compile_method(method, InvocationEntryBci,
iveresov@2610 348 CompilationPolicy::policy()->initial_compile_level(),
iveresov@1707 349 methodHandle(), 0, "must_be_compiled", CHECK);
duke@0 350 }
duke@0 351
duke@0 352 // Since the call stub sets up like the interpreter we call the from_interpreted_entry
duke@0 353 // so we can go compiled via a i2c. Otherwise initial entry method will always
duke@0 354 // run interpreted.
duke@0 355 address entry_point = method->from_interpreted_entry();
duke@0 356 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
duke@0 357 entry_point = method->interpreter_entry();
duke@0 358 }
duke@0 359
duke@0 360 // Figure out if the result value is an oop or not (Note: This is a different value
duke@0 361 // than result_type. result_type will be T_INT of oops. (it is about size)
duke@0 362 BasicType result_type = runtime_type_from(result);
duke@0 363 bool oop_result_flag = (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY);
duke@0 364
duke@0 365 // NOTE: if we move the computation of the result_val_address inside
duke@0 366 // the call to call_stub, the optimizer produces wrong code.
duke@0 367 intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
duke@0 368
duke@0 369 // Find receiver
duke@0 370 Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
duke@0 371
duke@0 372 // When we reenter Java, we need to reenable the yellow zone which
duke@0 373 // might already be disabled when we are in VM.
duke@0 374 if (thread->stack_yellow_zone_disabled()) {
duke@0 375 thread->reguard_stack();
duke@0 376 }
duke@0 377
duke@0 378 // Check that there are shadow pages available before changing thread state
duke@0 379 // to Java
duke@0 380 if (!os::stack_shadow_pages_available(THREAD, method)) {
duke@0 381 // Throw stack overflow exception with preinitialized exception.
coleenp@2378 382 Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
duke@0 383 return;
duke@0 384 } else {
duke@0 385 // Touch pages checked if the OS needs them to be touched to be mapped.
duke@0 386 os::bang_stack_shadow_pages();
duke@0 387 }
duke@0 388
duke@0 389 // do call
duke@0 390 { JavaCallWrapper link(method, receiver, result, CHECK);
duke@0 391 { HandleMark hm(thread); // HandleMark used by HandleMarkCleaner
duke@0 392
duke@0 393 StubRoutines::call_stub()(
duke@0 394 (address)&link,
duke@0 395 // (intptr_t*)&(result->_value), // see NOTE above (compiler problem)
duke@0 396 result_val_address, // see NOTE above (compiler problem)
duke@0 397 result_type,
duke@0 398 method(),
duke@0 399 entry_point,
duke@0 400 args->parameters(),
duke@0 401 args->size_of_parameters(),
duke@0 402 CHECK
duke@0 403 );
duke@0 404
duke@0 405 result = link.result(); // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
duke@0 406 // Preserve oop return value across possible gc points
duke@0 407 if (oop_result_flag) {
duke@0 408 thread->set_vm_result((oop) result->get_jobject());
duke@0 409 }
duke@0 410 }
duke@0 411 } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
duke@0 412
duke@0 413 // Check if a thread stop or suspend should be executed
duke@0 414 // The following assert was not realistic. Thread.stop can set that bit at any moment.
duke@0 415 //assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
duke@0 416
duke@0 417 // Restore possible oop return
duke@0 418 if (oop_result_flag) {
duke@0 419 result->set_jobject((jobject)thread->vm_result());
duke@0 420 thread->set_vm_result(NULL);
duke@0 421 }
duke@0 422 }
duke@0 423
duke@0 424
duke@0 425 //--------------------------------------------------------------------------------------
duke@0 426 // Implementation of JavaCallArguments
duke@0 427
duke@0 428 intptr_t* JavaCallArguments::parameters() {
duke@0 429 // First convert all handles to oops
duke@0 430 for(int i = 0; i < _size; i++) {
duke@0 431 if (_is_oop[i]) {
duke@0 432 // Handle conversion
hseigel@5466 433 _value[i] = cast_from_oop<intptr_t>(Handle::raw_resolve((oop *)_value[i]));
duke@0 434 }
duke@0 435 }
duke@0 436 // Return argument vector
twisti@1426 437 return _value;
duke@0 438 }
duke@0 439
duke@0 440
duke@0 441 class SignatureChekker : public SignatureIterator {
duke@0 442 private:
duke@0 443 bool *_is_oop;
duke@0 444 int _pos;
duke@0 445 BasicType _return_type;
poonam@465 446 intptr_t* _value;
poonam@465 447 Thread* _thread;
duke@0 448
duke@0 449 public:
duke@0 450 bool _is_return;
duke@0 451
coleenp@2069 452 SignatureChekker(Symbol* signature, BasicType return_type, bool is_static, bool* is_oop, intptr_t* value, Thread* thread) : SignatureIterator(signature) {
duke@0 453 _is_oop = is_oop;
duke@0 454 _is_return = false;
duke@0 455 _return_type = return_type;
duke@0 456 _pos = 0;
poonam@465 457 _value = value;
poonam@465 458 _thread = thread;
poonam@465 459
duke@0 460 if (!is_static) {
duke@0 461 check_value(true); // Receiver must be an oop
duke@0 462 }
duke@0 463 }
duke@0 464
duke@0 465 void check_value(bool type) {
duke@0 466 guarantee(_is_oop[_pos++] == type, "signature does not match pushed arguments");
duke@0 467 }
duke@0 468
duke@0 469 void check_doing_return(bool state) { _is_return = state; }
duke@0 470
duke@0 471 void check_return_type(BasicType t) {
duke@0 472 guarantee(_is_return && t == _return_type, "return type does not match");
duke@0 473 }
duke@0 474
duke@0 475 void check_int(BasicType t) {
duke@0 476 if (_is_return) {
duke@0 477 check_return_type(t);
duke@0 478 return;
duke@0 479 }
duke@0 480 check_value(false);
duke@0 481 }
duke@0 482
duke@0 483 void check_double(BasicType t) { check_long(t); }
duke@0 484
duke@0 485 void check_long(BasicType t) {
duke@0 486 if (_is_return) {
duke@0 487 check_return_type(t);
duke@0 488 return;
duke@0 489 }
duke@0 490
duke@0 491 check_value(false);
duke@0 492 check_value(false);
duke@0 493 }
duke@0 494
duke@0 495 void check_obj(BasicType t) {
duke@0 496 if (_is_return) {
duke@0 497 check_return_type(t);
duke@0 498 return;
duke@0 499 }
poonam@465 500
poonam@465 501 // verify handle and the oop pointed to by handle
poonam@465 502 int p = _pos;
poonam@465 503 bool bad = false;
poonam@465 504 // If argument is oop
poonam@465 505 if (_is_oop[p]) {
poonam@465 506 intptr_t v = _value[p];
poonam@465 507 if (v != 0 ) {
poonam@465 508 size_t t = (size_t)v;
poonam@498 509 bad = (t < (size_t)os::vm_page_size() ) || !Handle::raw_resolve((oop *)v)->is_oop_or_null(true);
poonam@465 510 if (CheckJNICalls && bad) {
poonam@465 511 ReportJNIFatalError((JavaThread*)_thread, "Bad JNI oop argument");
poonam@465 512 }
poonam@465 513 }
poonam@465 514 // for the regular debug case.
poonam@465 515 assert(!bad, "Bad JNI oop argument");
poonam@465 516 }
poonam@465 517
duke@0 518 check_value(true);
duke@0 519 }
duke@0 520
duke@0 521 void do_bool() { check_int(T_BOOLEAN); }
duke@0 522 void do_char() { check_int(T_CHAR); }
duke@0 523 void do_float() { check_int(T_FLOAT); }
duke@0 524 void do_double() { check_double(T_DOUBLE); }
duke@0 525 void do_byte() { check_int(T_BYTE); }
duke@0 526 void do_short() { check_int(T_SHORT); }
duke@0 527 void do_int() { check_int(T_INT); }
duke@0 528 void do_long() { check_long(T_LONG); }
duke@0 529 void do_void() { check_return_type(T_VOID); }
duke@0 530 void do_object(int begin, int end) { check_obj(T_OBJECT); }
duke@0 531 void do_array(int begin, int end) { check_obj(T_OBJECT); }
duke@0 532 };
duke@0 533
poonam@465 534
duke@0 535 void JavaCallArguments::verify(methodHandle method, BasicType return_type,
duke@0 536 Thread *thread) {
duke@0 537 guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
duke@0 538
duke@0 539 // Treat T_OBJECT and T_ARRAY as the same
duke@0 540 if (return_type == T_ARRAY) return_type = T_OBJECT;
duke@0 541
duke@0 542 // Check that oop information is correct
coleenp@2069 543 Symbol* signature = method->signature();
duke@0 544
poonam@465 545 SignatureChekker sc(signature, return_type, method->is_static(),_is_oop, _value, thread);
duke@0 546 sc.iterate_parameters();
duke@0 547 sc.check_doing_return(true);
duke@0 548 sc.iterate_returntype();
duke@0 549 }