src/share/vm/runtime/javaCalls.cpp

Fri, 24 Jun 2016 17:12:13 +0800

author
aoqi<aoqi@loongson.cn>
date
Fri, 24 Jun 2016 17:12:13 +0800
changeset 25
873fd82b133d
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

[Code Reorganization] Removed GC related modifications made by Loongson, for example, UseOldNUMA.

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

mercurial