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