Thu, 24 May 2018 17:06:56 +0800
Merge
aoqi@0 | 1 | /* |
kevinw@8368 | 2 | * Copyright (c) 1997, 2016, 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@1 | 25 | /* |
aoqi@1 | 26 | * This file has been modified by Loongson Technology in 2015. These |
aoqi@1 | 27 | * modifications are Copyright (c) 2015 Loongson Technology, and are made |
aoqi@1 | 28 | * available on the same license terms set forth above. |
aoqi@1 | 29 | */ |
aoqi@1 | 30 | |
aoqi@0 | 31 | #include "precompiled.hpp" |
aoqi@0 | 32 | #include "classfile/systemDictionary.hpp" |
aoqi@0 | 33 | #include "classfile/vmSymbols.hpp" |
aoqi@0 | 34 | #include "compiler/compileBroker.hpp" |
aoqi@0 | 35 | #include "compiler/disassembler.hpp" |
aoqi@0 | 36 | #include "gc_interface/collectedHeap.hpp" |
aoqi@0 | 37 | #include "interpreter/interpreter.hpp" |
aoqi@0 | 38 | #include "interpreter/interpreterRuntime.hpp" |
aoqi@0 | 39 | #include "interpreter/linkResolver.hpp" |
aoqi@0 | 40 | #include "interpreter/templateTable.hpp" |
aoqi@0 | 41 | #include "memory/oopFactory.hpp" |
aoqi@0 | 42 | #include "memory/universe.inline.hpp" |
aoqi@0 | 43 | #include "oops/constantPool.hpp" |
aoqi@0 | 44 | #include "oops/instanceKlass.hpp" |
aoqi@0 | 45 | #include "oops/methodData.hpp" |
aoqi@0 | 46 | #include "oops/objArrayKlass.hpp" |
aoqi@0 | 47 | #include "oops/oop.inline.hpp" |
aoqi@0 | 48 | #include "oops/symbol.hpp" |
aoqi@0 | 49 | #include "prims/jvmtiExport.hpp" |
aoqi@0 | 50 | #include "prims/nativeLookup.hpp" |
aoqi@0 | 51 | #include "runtime/biasedLocking.hpp" |
aoqi@0 | 52 | #include "runtime/compilationPolicy.hpp" |
aoqi@0 | 53 | #include "runtime/deoptimization.hpp" |
aoqi@0 | 54 | #include "runtime/fieldDescriptor.hpp" |
aoqi@0 | 55 | #include "runtime/handles.inline.hpp" |
aoqi@0 | 56 | #include "runtime/interfaceSupport.hpp" |
aoqi@0 | 57 | #include "runtime/java.hpp" |
aoqi@0 | 58 | #include "runtime/jfieldIDWorkaround.hpp" |
aoqi@0 | 59 | #include "runtime/osThread.hpp" |
aoqi@0 | 60 | #include "runtime/sharedRuntime.hpp" |
aoqi@0 | 61 | #include "runtime/stubRoutines.hpp" |
aoqi@0 | 62 | #include "runtime/synchronizer.hpp" |
aoqi@0 | 63 | #include "runtime/threadCritical.hpp" |
aoqi@0 | 64 | #include "utilities/events.hpp" |
aoqi@0 | 65 | #ifdef TARGET_ARCH_x86 |
aoqi@0 | 66 | # include "vm_version_x86.hpp" |
aoqi@0 | 67 | #endif |
aoqi@1 | 68 | #ifdef TARGET_ARCH_mips |
aoqi@1 | 69 | # include "vm_version_mips.hpp" |
aoqi@1 | 70 | #endif |
aoqi@0 | 71 | #ifdef TARGET_ARCH_sparc |
aoqi@0 | 72 | # include "vm_version_sparc.hpp" |
aoqi@0 | 73 | #endif |
aoqi@0 | 74 | #ifdef TARGET_ARCH_zero |
aoqi@0 | 75 | # include "vm_version_zero.hpp" |
aoqi@0 | 76 | #endif |
aoqi@0 | 77 | #ifdef TARGET_ARCH_arm |
aoqi@0 | 78 | # include "vm_version_arm.hpp" |
aoqi@0 | 79 | #endif |
aoqi@0 | 80 | #ifdef TARGET_ARCH_ppc |
aoqi@0 | 81 | # include "vm_version_ppc.hpp" |
aoqi@0 | 82 | #endif |
aoqi@0 | 83 | #ifdef COMPILER2 |
aoqi@0 | 84 | #include "opto/runtime.hpp" |
aoqi@0 | 85 | #endif |
aoqi@0 | 86 | |
aoqi@0 | 87 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
aoqi@0 | 88 | |
aoqi@0 | 89 | class UnlockFlagSaver { |
aoqi@0 | 90 | private: |
aoqi@0 | 91 | JavaThread* _thread; |
aoqi@0 | 92 | bool _do_not_unlock; |
aoqi@0 | 93 | public: |
aoqi@0 | 94 | UnlockFlagSaver(JavaThread* t) { |
aoqi@0 | 95 | _thread = t; |
aoqi@0 | 96 | _do_not_unlock = t->do_not_unlock_if_synchronized(); |
aoqi@0 | 97 | t->set_do_not_unlock_if_synchronized(false); |
aoqi@0 | 98 | } |
aoqi@0 | 99 | ~UnlockFlagSaver() { |
aoqi@0 | 100 | _thread->set_do_not_unlock_if_synchronized(_do_not_unlock); |
aoqi@0 | 101 | } |
aoqi@0 | 102 | }; |
aoqi@0 | 103 | |
aoqi@0 | 104 | //------------------------------------------------------------------------------------------------------------------------ |
aoqi@0 | 105 | // State accessors |
aoqi@0 | 106 | |
aoqi@0 | 107 | void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) { |
aoqi@0 | 108 | last_frame(thread).interpreter_frame_set_bcp(bcp); |
aoqi@0 | 109 | if (ProfileInterpreter) { |
aoqi@0 | 110 | // ProfileTraps uses MDOs independently of ProfileInterpreter. |
aoqi@0 | 111 | // That is why we must check both ProfileInterpreter and mdo != NULL. |
aoqi@0 | 112 | MethodData* mdo = last_frame(thread).interpreter_frame_method()->method_data(); |
aoqi@0 | 113 | if (mdo != NULL) { |
aoqi@0 | 114 | NEEDS_CLEANUP; |
aoqi@0 | 115 | last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci())); |
aoqi@0 | 116 | } |
aoqi@0 | 117 | } |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | //------------------------------------------------------------------------------------------------------------------------ |
aoqi@0 | 121 | // Constants |
aoqi@0 | 122 | |
aoqi@0 | 123 | |
aoqi@0 | 124 | IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide)) |
aoqi@0 | 125 | // access constant pool |
aoqi@0 | 126 | ConstantPool* pool = method(thread)->constants(); |
aoqi@0 | 127 | int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc); |
aoqi@0 | 128 | constantTag tag = pool->tag_at(index); |
aoqi@0 | 129 | |
aoqi@0 | 130 | assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call"); |
aoqi@0 | 131 | Klass* klass = pool->klass_at(index, CHECK); |
aoqi@0 | 132 | oop java_class = klass->java_mirror(); |
aoqi@0 | 133 | thread->set_vm_result(java_class); |
aoqi@0 | 134 | IRT_END |
aoqi@0 | 135 | |
aoqi@0 | 136 | IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) { |
aoqi@0 | 137 | assert(bytecode == Bytecodes::_fast_aldc || |
aoqi@0 | 138 | bytecode == Bytecodes::_fast_aldc_w, "wrong bc"); |
aoqi@0 | 139 | ResourceMark rm(thread); |
aoqi@0 | 140 | methodHandle m (thread, method(thread)); |
aoqi@0 | 141 | Bytecode_loadconstant ldc(m, bci(thread)); |
aoqi@0 | 142 | oop result = ldc.resolve_constant(CHECK); |
aoqi@0 | 143 | #ifdef ASSERT |
aoqi@0 | 144 | { |
aoqi@0 | 145 | // The bytecode wrappers aren't GC-safe so construct a new one |
aoqi@0 | 146 | Bytecode_loadconstant ldc2(m, bci(thread)); |
aoqi@0 | 147 | oop coop = m->constants()->resolved_references()->obj_at(ldc2.cache_index()); |
aoqi@0 | 148 | assert(result == coop, "expected result for assembly code"); |
aoqi@0 | 149 | } |
aoqi@0 | 150 | #endif |
aoqi@0 | 151 | thread->set_vm_result(result); |
aoqi@0 | 152 | } |
aoqi@0 | 153 | IRT_END |
aoqi@0 | 154 | |
aoqi@0 | 155 | |
aoqi@0 | 156 | //------------------------------------------------------------------------------------------------------------------------ |
aoqi@0 | 157 | // Allocation |
aoqi@0 | 158 | |
aoqi@0 | 159 | IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, ConstantPool* pool, int index)) |
aoqi@0 | 160 | Klass* k_oop = pool->klass_at(index, CHECK); |
aoqi@0 | 161 | instanceKlassHandle klass (THREAD, k_oop); |
aoqi@0 | 162 | |
aoqi@0 | 163 | // Make sure we are not instantiating an abstract klass |
aoqi@0 | 164 | klass->check_valid_for_instantiation(true, CHECK); |
aoqi@0 | 165 | |
aoqi@0 | 166 | // Make sure klass is initialized |
aoqi@0 | 167 | klass->initialize(CHECK); |
aoqi@0 | 168 | |
aoqi@0 | 169 | // At this point the class may not be fully initialized |
aoqi@0 | 170 | // because of recursive initialization. If it is fully |
aoqi@0 | 171 | // initialized & has_finalized is not set, we rewrite |
aoqi@0 | 172 | // it into its fast version (Note: no locking is needed |
aoqi@0 | 173 | // here since this is an atomic byte write and can be |
aoqi@0 | 174 | // done more than once). |
aoqi@0 | 175 | // |
aoqi@0 | 176 | // Note: In case of classes with has_finalized we don't |
aoqi@0 | 177 | // rewrite since that saves us an extra check in |
aoqi@0 | 178 | // the fast version which then would call the |
aoqi@0 | 179 | // slow version anyway (and do a call back into |
aoqi@0 | 180 | // Java). |
aoqi@0 | 181 | // If we have a breakpoint, then we don't rewrite |
aoqi@0 | 182 | // because the _breakpoint bytecode would be lost. |
aoqi@0 | 183 | oop obj = klass->allocate_instance(CHECK); |
aoqi@0 | 184 | thread->set_vm_result(obj); |
aoqi@0 | 185 | IRT_END |
aoqi@0 | 186 | |
aoqi@0 | 187 | |
aoqi@0 | 188 | IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size)) |
aoqi@0 | 189 | oop obj = oopFactory::new_typeArray(type, size, CHECK); |
aoqi@0 | 190 | thread->set_vm_result(obj); |
aoqi@0 | 191 | IRT_END |
aoqi@0 | 192 | |
aoqi@0 | 193 | |
aoqi@0 | 194 | IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size)) |
aoqi@0 | 195 | // Note: no oopHandle for pool & klass needed since they are not used |
aoqi@0 | 196 | // anymore after new_objArray() and no GC can happen before. |
aoqi@0 | 197 | // (This may have to change if this code changes!) |
aoqi@0 | 198 | Klass* klass = pool->klass_at(index, CHECK); |
aoqi@0 | 199 | objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK); |
aoqi@0 | 200 | thread->set_vm_result(obj); |
aoqi@0 | 201 | IRT_END |
aoqi@0 | 202 | |
aoqi@0 | 203 | |
aoqi@0 | 204 | IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address)) |
aoqi@0 | 205 | // We may want to pass in more arguments - could make this slightly faster |
aoqi@0 | 206 | ConstantPool* constants = method(thread)->constants(); |
aoqi@0 | 207 | int i = get_index_u2(thread, Bytecodes::_multianewarray); |
aoqi@0 | 208 | Klass* klass = constants->klass_at(i, CHECK); |
aoqi@0 | 209 | int nof_dims = number_of_dimensions(thread); |
aoqi@0 | 210 | assert(klass->is_klass(), "not a class"); |
aoqi@0 | 211 | assert(nof_dims >= 1, "multianewarray rank must be nonzero"); |
aoqi@0 | 212 | |
aoqi@0 | 213 | // We must create an array of jints to pass to multi_allocate. |
aoqi@0 | 214 | ResourceMark rm(thread); |
aoqi@0 | 215 | const int small_dims = 10; |
aoqi@0 | 216 | jint dim_array[small_dims]; |
aoqi@0 | 217 | jint *dims = &dim_array[0]; |
aoqi@0 | 218 | if (nof_dims > small_dims) { |
aoqi@0 | 219 | dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims); |
aoqi@0 | 220 | } |
aoqi@0 | 221 | for (int index = 0; index < nof_dims; index++) { |
aoqi@0 | 222 | // offset from first_size_address is addressed as local[index] |
aoqi@0 | 223 | int n = Interpreter::local_offset_in_bytes(index)/jintSize; |
aoqi@0 | 224 | dims[index] = first_size_address[n]; |
aoqi@0 | 225 | } |
aoqi@0 | 226 | oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK); |
aoqi@0 | 227 | thread->set_vm_result(obj); |
aoqi@0 | 228 | IRT_END |
aoqi@0 | 229 | |
aoqi@0 | 230 | |
aoqi@0 | 231 | IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj)) |
aoqi@0 | 232 | assert(obj->is_oop(), "must be a valid oop"); |
aoqi@0 | 233 | assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise"); |
aoqi@0 | 234 | InstanceKlass::register_finalizer(instanceOop(obj), CHECK); |
aoqi@0 | 235 | IRT_END |
aoqi@0 | 236 | |
aoqi@0 | 237 | |
aoqi@0 | 238 | // Quicken instance-of and check-cast bytecodes |
aoqi@0 | 239 | IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread)) |
aoqi@0 | 240 | // Force resolving; quicken the bytecode |
aoqi@0 | 241 | int which = get_index_u2(thread, Bytecodes::_checkcast); |
aoqi@0 | 242 | ConstantPool* cpool = method(thread)->constants(); |
aoqi@0 | 243 | // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded |
aoqi@0 | 244 | // program we might have seen an unquick'd bytecode in the interpreter but have another |
aoqi@0 | 245 | // thread quicken the bytecode before we get here. |
aoqi@0 | 246 | // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" ); |
aoqi@0 | 247 | Klass* klass = cpool->klass_at(which, CHECK); |
aoqi@0 | 248 | thread->set_vm_result_2(klass); |
aoqi@0 | 249 | IRT_END |
aoqi@0 | 250 | |
aoqi@0 | 251 | |
aoqi@0 | 252 | //------------------------------------------------------------------------------------------------------------------------ |
aoqi@0 | 253 | // Exceptions |
aoqi@0 | 254 | |
aoqi@0 | 255 | void InterpreterRuntime::note_trap_inner(JavaThread* thread, int reason, |
aoqi@0 | 256 | methodHandle trap_method, int trap_bci, TRAPS) { |
aoqi@0 | 257 | if (trap_method.not_null()) { |
aoqi@0 | 258 | MethodData* trap_mdo = trap_method->method_data(); |
aoqi@0 | 259 | if (trap_mdo == NULL) { |
aoqi@0 | 260 | Method::build_interpreter_method_data(trap_method, THREAD); |
aoqi@0 | 261 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 262 | assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), |
aoqi@0 | 263 | "we expect only an OOM error here"); |
aoqi@0 | 264 | CLEAR_PENDING_EXCEPTION; |
aoqi@0 | 265 | } |
aoqi@0 | 266 | trap_mdo = trap_method->method_data(); |
aoqi@0 | 267 | // and fall through... |
aoqi@0 | 268 | } |
aoqi@0 | 269 | if (trap_mdo != NULL) { |
aoqi@0 | 270 | // Update per-method count of trap events. The interpreter |
aoqi@0 | 271 | // is updating the MDO to simulate the effect of compiler traps. |
aoqi@0 | 272 | Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason); |
aoqi@0 | 273 | } |
aoqi@0 | 274 | } |
aoqi@0 | 275 | } |
aoqi@0 | 276 | |
aoqi@0 | 277 | // Assume the compiler is (or will be) interested in this event. |
aoqi@0 | 278 | // If necessary, create an MDO to hold the information, and record it. |
aoqi@0 | 279 | void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) { |
aoqi@0 | 280 | assert(ProfileTraps, "call me only if profiling"); |
aoqi@0 | 281 | methodHandle trap_method(thread, method(thread)); |
aoqi@0 | 282 | int trap_bci = trap_method->bci_from(bcp(thread)); |
aoqi@0 | 283 | note_trap_inner(thread, reason, trap_method, trap_bci, THREAD); |
aoqi@0 | 284 | } |
aoqi@0 | 285 | |
aoqi@0 | 286 | #ifdef CC_INTERP |
aoqi@0 | 287 | // As legacy note_trap, but we have more arguments. |
aoqi@0 | 288 | IRT_ENTRY(void, InterpreterRuntime::note_trap(JavaThread* thread, int reason, Method *method, int trap_bci)) |
aoqi@0 | 289 | methodHandle trap_method(method); |
aoqi@0 | 290 | note_trap_inner(thread, reason, trap_method, trap_bci, THREAD); |
aoqi@0 | 291 | IRT_END |
aoqi@0 | 292 | |
aoqi@0 | 293 | // Class Deoptimization is not visible in BytecodeInterpreter, so we need a wrapper |
aoqi@0 | 294 | // for each exception. |
aoqi@0 | 295 | void InterpreterRuntime::note_nullCheck_trap(JavaThread* thread, Method *method, int trap_bci) |
aoqi@0 | 296 | { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_null_check, method, trap_bci); } |
aoqi@0 | 297 | void InterpreterRuntime::note_div0Check_trap(JavaThread* thread, Method *method, int trap_bci) |
aoqi@0 | 298 | { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_div0_check, method, trap_bci); } |
aoqi@0 | 299 | void InterpreterRuntime::note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci) |
aoqi@0 | 300 | { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_range_check, method, trap_bci); } |
aoqi@0 | 301 | void InterpreterRuntime::note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci) |
aoqi@0 | 302 | { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_class_check, method, trap_bci); } |
aoqi@0 | 303 | void InterpreterRuntime::note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci) |
aoqi@0 | 304 | { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_array_check, method, trap_bci); } |
aoqi@0 | 305 | #endif // CC_INTERP |
aoqi@0 | 306 | |
aoqi@0 | 307 | |
aoqi@0 | 308 | static Handle get_preinitialized_exception(Klass* k, TRAPS) { |
aoqi@0 | 309 | // get klass |
aoqi@0 | 310 | InstanceKlass* klass = InstanceKlass::cast(k); |
aoqi@0 | 311 | assert(klass->is_initialized(), |
aoqi@0 | 312 | "this klass should have been initialized during VM initialization"); |
aoqi@0 | 313 | // create instance - do not call constructor since we may have no |
aoqi@0 | 314 | // (java) stack space left (should assert constructor is empty) |
aoqi@0 | 315 | Handle exception; |
aoqi@0 | 316 | oop exception_oop = klass->allocate_instance(CHECK_(exception)); |
aoqi@0 | 317 | exception = Handle(THREAD, exception_oop); |
aoqi@0 | 318 | if (StackTraceInThrowable) { |
aoqi@0 | 319 | java_lang_Throwable::fill_in_stack_trace(exception); |
aoqi@0 | 320 | } |
aoqi@0 | 321 | return exception; |
aoqi@0 | 322 | } |
aoqi@0 | 323 | |
aoqi@0 | 324 | // Special handling for stack overflow: since we don't have any (java) stack |
aoqi@0 | 325 | // space left we use the pre-allocated & pre-initialized StackOverflowError |
aoqi@0 | 326 | // klass to create an stack overflow error instance. We do not call its |
aoqi@0 | 327 | // constructor for the same reason (it is empty, anyway). |
aoqi@0 | 328 | IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread)) |
aoqi@0 | 329 | Handle exception = get_preinitialized_exception( |
aoqi@0 | 330 | SystemDictionary::StackOverflowError_klass(), |
aoqi@0 | 331 | CHECK); |
aoqi@0 | 332 | THROW_HANDLE(exception); |
aoqi@0 | 333 | IRT_END |
aoqi@0 | 334 | |
aoqi@0 | 335 | |
aoqi@0 | 336 | IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message)) |
aoqi@0 | 337 | // lookup exception klass |
aoqi@0 | 338 | TempNewSymbol s = SymbolTable::new_symbol(name, CHECK); |
aoqi@0 | 339 | if (ProfileTraps) { |
aoqi@0 | 340 | if (s == vmSymbols::java_lang_ArithmeticException()) { |
aoqi@0 | 341 | note_trap(thread, Deoptimization::Reason_div0_check, CHECK); |
aoqi@0 | 342 | } else if (s == vmSymbols::java_lang_NullPointerException()) { |
aoqi@0 | 343 | note_trap(thread, Deoptimization::Reason_null_check, CHECK); |
aoqi@0 | 344 | } |
aoqi@0 | 345 | } |
aoqi@0 | 346 | // create exception |
aoqi@0 | 347 | Handle exception = Exceptions::new_exception(thread, s, message); |
aoqi@0 | 348 | thread->set_vm_result(exception()); |
aoqi@0 | 349 | IRT_END |
aoqi@0 | 350 | |
aoqi@0 | 351 | |
aoqi@0 | 352 | IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj)) |
aoqi@0 | 353 | ResourceMark rm(thread); |
aoqi@0 | 354 | const char* klass_name = obj->klass()->external_name(); |
aoqi@0 | 355 | // lookup exception klass |
aoqi@0 | 356 | TempNewSymbol s = SymbolTable::new_symbol(name, CHECK); |
aoqi@0 | 357 | if (ProfileTraps) { |
aoqi@0 | 358 | note_trap(thread, Deoptimization::Reason_class_check, CHECK); |
aoqi@0 | 359 | } |
aoqi@0 | 360 | // create exception, with klass name as detail message |
aoqi@0 | 361 | Handle exception = Exceptions::new_exception(thread, s, klass_name); |
aoqi@0 | 362 | thread->set_vm_result(exception()); |
aoqi@0 | 363 | IRT_END |
aoqi@0 | 364 | |
aoqi@0 | 365 | |
aoqi@0 | 366 | IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index)) |
aoqi@0 | 367 | char message[jintAsStringSize]; |
aoqi@0 | 368 | // lookup exception klass |
aoqi@0 | 369 | TempNewSymbol s = SymbolTable::new_symbol(name, CHECK); |
aoqi@0 | 370 | if (ProfileTraps) { |
aoqi@0 | 371 | note_trap(thread, Deoptimization::Reason_range_check, CHECK); |
aoqi@0 | 372 | } |
aoqi@0 | 373 | // create exception |
aoqi@0 | 374 | sprintf(message, "%d", index); |
aoqi@0 | 375 | THROW_MSG(s, message); |
aoqi@0 | 376 | IRT_END |
aoqi@0 | 377 | |
aoqi@0 | 378 | IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException( |
aoqi@0 | 379 | JavaThread* thread, oopDesc* obj)) |
aoqi@0 | 380 | |
aoqi@0 | 381 | ResourceMark rm(thread); |
aoqi@0 | 382 | char* message = SharedRuntime::generate_class_cast_message( |
aoqi@0 | 383 | thread, obj->klass()->external_name()); |
aoqi@0 | 384 | |
aoqi@0 | 385 | if (ProfileTraps) { |
aoqi@0 | 386 | note_trap(thread, Deoptimization::Reason_class_check, CHECK); |
aoqi@0 | 387 | } |
aoqi@0 | 388 | |
aoqi@0 | 389 | // create exception |
aoqi@0 | 390 | THROW_MSG(vmSymbols::java_lang_ClassCastException(), message); |
aoqi@0 | 391 | IRT_END |
aoqi@0 | 392 | |
aoqi@0 | 393 | // exception_handler_for_exception(...) returns the continuation address, |
aoqi@0 | 394 | // the exception oop (via TLS) and sets the bci/bcp for the continuation. |
aoqi@0 | 395 | // The exception oop is returned to make sure it is preserved over GC (it |
aoqi@0 | 396 | // is only on the stack if the exception was thrown explicitly via athrow). |
aoqi@0 | 397 | // During this operation, the expression stack contains the values for the |
aoqi@0 | 398 | // bci where the exception happened. If the exception was propagated back |
aoqi@0 | 399 | // from a call, the expression stack contains the values for the bci at the |
aoqi@0 | 400 | // invoke w/o arguments (i.e., as if one were inside the call). |
aoqi@0 | 401 | IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception)) |
aoqi@0 | 402 | |
aoqi@0 | 403 | Handle h_exception(thread, exception); |
aoqi@0 | 404 | methodHandle h_method (thread, method(thread)); |
aoqi@0 | 405 | constantPoolHandle h_constants(thread, h_method->constants()); |
aoqi@0 | 406 | bool should_repeat; |
aoqi@0 | 407 | int handler_bci; |
aoqi@0 | 408 | int current_bci = bci(thread); |
aoqi@0 | 409 | |
roland@7419 | 410 | if (thread->frames_to_pop_failed_realloc() > 0) { |
roland@7419 | 411 | // Allocation of scalar replaced object used in this frame |
roland@7419 | 412 | // failed. Unconditionally pop the frame. |
roland@7419 | 413 | thread->dec_frames_to_pop_failed_realloc(); |
roland@7419 | 414 | thread->set_vm_result(h_exception()); |
roland@7419 | 415 | // If the method is synchronized we already unlocked the monitor |
roland@7419 | 416 | // during deoptimization so the interpreter needs to skip it when |
roland@7419 | 417 | // the frame is popped. |
roland@7419 | 418 | thread->set_do_not_unlock_if_synchronized(true); |
roland@7600 | 419 | #ifdef CC_INTERP |
roland@7600 | 420 | return (address) -1; |
roland@7600 | 421 | #else |
roland@7419 | 422 | return Interpreter::remove_activation_entry(); |
roland@7600 | 423 | #endif |
roland@7419 | 424 | } |
roland@7419 | 425 | |
aoqi@0 | 426 | // Need to do this check first since when _do_not_unlock_if_synchronized |
aoqi@0 | 427 | // is set, we don't want to trigger any classloading which may make calls |
aoqi@0 | 428 | // into java, or surprisingly find a matching exception handler for bci 0 |
aoqi@0 | 429 | // since at this moment the method hasn't been "officially" entered yet. |
aoqi@0 | 430 | if (thread->do_not_unlock_if_synchronized()) { |
aoqi@0 | 431 | ResourceMark rm; |
aoqi@0 | 432 | assert(current_bci == 0, "bci isn't zero for do_not_unlock_if_synchronized"); |
aoqi@0 | 433 | thread->set_vm_result(exception); |
aoqi@0 | 434 | #ifdef CC_INTERP |
aoqi@0 | 435 | return (address) -1; |
aoqi@0 | 436 | #else |
aoqi@0 | 437 | return Interpreter::remove_activation_entry(); |
aoqi@0 | 438 | #endif |
aoqi@0 | 439 | } |
aoqi@0 | 440 | |
aoqi@0 | 441 | do { |
aoqi@0 | 442 | should_repeat = false; |
aoqi@0 | 443 | |
aoqi@0 | 444 | // assertions |
aoqi@0 | 445 | #ifdef ASSERT |
aoqi@0 | 446 | assert(h_exception.not_null(), "NULL exceptions should be handled by athrow"); |
aoqi@0 | 447 | assert(h_exception->is_oop(), "just checking"); |
aoqi@0 | 448 | // Check that exception is a subclass of Throwable, otherwise we have a VerifyError |
aoqi@0 | 449 | if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) { |
aoqi@0 | 450 | if (ExitVMOnVerifyError) vm_exit(-1); |
aoqi@0 | 451 | ShouldNotReachHere(); |
aoqi@0 | 452 | } |
aoqi@0 | 453 | #endif |
aoqi@0 | 454 | |
aoqi@0 | 455 | // tracing |
aoqi@0 | 456 | if (TraceExceptions) { |
aoqi@0 | 457 | ttyLocker ttyl; |
aoqi@0 | 458 | ResourceMark rm(thread); |
aoqi@0 | 459 | tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception()); |
aoqi@0 | 460 | tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string()); |
aoqi@0 | 461 | tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread); |
aoqi@0 | 462 | } |
aoqi@0 | 463 | // Don't go paging in something which won't be used. |
aoqi@0 | 464 | // else if (extable->length() == 0) { |
aoqi@0 | 465 | // // disabled for now - interpreter is not using shortcut yet |
aoqi@0 | 466 | // // (shortcut is not to call runtime if we have no exception handlers) |
aoqi@0 | 467 | // // warning("performance bug: should not call runtime if method has no exception handlers"); |
aoqi@0 | 468 | // } |
aoqi@0 | 469 | // for AbortVMOnException flag |
aoqi@0 | 470 | NOT_PRODUCT(Exceptions::debug_check_abort(h_exception)); |
aoqi@0 | 471 | |
aoqi@0 | 472 | // exception handler lookup |
aoqi@0 | 473 | KlassHandle h_klass(THREAD, h_exception->klass()); |
aoqi@0 | 474 | handler_bci = Method::fast_exception_handler_bci_for(h_method, h_klass, current_bci, THREAD); |
aoqi@0 | 475 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 476 | // We threw an exception while trying to find the exception handler. |
aoqi@0 | 477 | // Transfer the new exception to the exception handle which will |
aoqi@0 | 478 | // be set into thread local storage, and do another lookup for an |
aoqi@0 | 479 | // exception handler for this exception, this time starting at the |
aoqi@0 | 480 | // BCI of the exception handler which caused the exception to be |
aoqi@0 | 481 | // thrown (bug 4307310). |
aoqi@0 | 482 | h_exception = Handle(THREAD, PENDING_EXCEPTION); |
aoqi@0 | 483 | CLEAR_PENDING_EXCEPTION; |
aoqi@0 | 484 | if (handler_bci >= 0) { |
aoqi@0 | 485 | current_bci = handler_bci; |
aoqi@0 | 486 | should_repeat = true; |
aoqi@0 | 487 | } |
aoqi@0 | 488 | } |
aoqi@0 | 489 | } while (should_repeat == true); |
aoqi@0 | 490 | |
aoqi@0 | 491 | // notify JVMTI of an exception throw; JVMTI will detect if this is a first |
aoqi@0 | 492 | // time throw or a stack unwinding throw and accordingly notify the debugger |
aoqi@0 | 493 | if (JvmtiExport::can_post_on_exceptions()) { |
aoqi@0 | 494 | JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception()); |
aoqi@0 | 495 | } |
aoqi@0 | 496 | |
aoqi@0 | 497 | #ifdef CC_INTERP |
aoqi@0 | 498 | address continuation = (address)(intptr_t) handler_bci; |
aoqi@0 | 499 | #else |
aoqi@0 | 500 | address continuation = NULL; |
aoqi@0 | 501 | #endif |
aoqi@0 | 502 | address handler_pc = NULL; |
aoqi@0 | 503 | if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) { |
aoqi@0 | 504 | // Forward exception to callee (leaving bci/bcp untouched) because (a) no |
aoqi@0 | 505 | // handler in this method, or (b) after a stack overflow there is not yet |
aoqi@0 | 506 | // enough stack space available to reprotect the stack. |
aoqi@0 | 507 | #ifndef CC_INTERP |
aoqi@0 | 508 | continuation = Interpreter::remove_activation_entry(); |
aoqi@0 | 509 | #endif |
aoqi@0 | 510 | // Count this for compilation purposes |
aoqi@0 | 511 | h_method->interpreter_throwout_increment(THREAD); |
aoqi@0 | 512 | } else { |
aoqi@0 | 513 | // handler in this method => change bci/bcp to handler bci/bcp and continue there |
aoqi@0 | 514 | handler_pc = h_method->code_base() + handler_bci; |
aoqi@0 | 515 | #ifndef CC_INTERP |
aoqi@0 | 516 | set_bcp_and_mdp(handler_pc, thread); |
aoqi@0 | 517 | continuation = Interpreter::dispatch_table(vtos)[*handler_pc]; |
aoqi@0 | 518 | #endif |
aoqi@0 | 519 | } |
aoqi@0 | 520 | // notify debugger of an exception catch |
aoqi@0 | 521 | // (this is good for exceptions caught in native methods as well) |
aoqi@0 | 522 | if (JvmtiExport::can_post_on_exceptions()) { |
aoqi@0 | 523 | JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL)); |
aoqi@0 | 524 | } |
aoqi@0 | 525 | |
aoqi@0 | 526 | thread->set_vm_result(h_exception()); |
aoqi@0 | 527 | return continuation; |
aoqi@0 | 528 | IRT_END |
aoqi@0 | 529 | |
aoqi@0 | 530 | |
aoqi@0 | 531 | IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread)) |
aoqi@0 | 532 | assert(thread->has_pending_exception(), "must only ne called if there's an exception pending"); |
aoqi@0 | 533 | // nothing to do - eventually we should remove this code entirely (see comments @ call sites) |
aoqi@0 | 534 | IRT_END |
aoqi@0 | 535 | |
aoqi@0 | 536 | |
aoqi@0 | 537 | IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread)) |
aoqi@0 | 538 | THROW(vmSymbols::java_lang_AbstractMethodError()); |
aoqi@0 | 539 | IRT_END |
aoqi@0 | 540 | |
aoqi@0 | 541 | |
aoqi@0 | 542 | IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread)) |
aoqi@0 | 543 | THROW(vmSymbols::java_lang_IncompatibleClassChangeError()); |
aoqi@0 | 544 | IRT_END |
aoqi@0 | 545 | |
aoqi@0 | 546 | |
aoqi@0 | 547 | //------------------------------------------------------------------------------------------------------------------------ |
aoqi@0 | 548 | // Fields |
aoqi@0 | 549 | // |
aoqi@0 | 550 | |
aoqi@0 | 551 | IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode)) |
aoqi@0 | 552 | // resolve field |
aoqi@0 | 553 | fieldDescriptor info; |
aoqi@0 | 554 | constantPoolHandle pool(thread, method(thread)->constants()); |
aoqi@0 | 555 | bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_putstatic); |
aoqi@0 | 556 | bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic); |
aoqi@0 | 557 | |
aoqi@0 | 558 | { |
aoqi@0 | 559 | JvmtiHideSingleStepping jhss(thread); |
aoqi@0 | 560 | LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode), |
aoqi@0 | 561 | bytecode, CHECK); |
aoqi@0 | 562 | } // end JvmtiHideSingleStepping |
aoqi@0 | 563 | |
aoqi@0 | 564 | // check if link resolution caused cpCache to be updated |
aoqi@0 | 565 | if (already_resolved(thread)) return; |
aoqi@0 | 566 | |
aoqi@0 | 567 | // compute auxiliary field attributes |
aoqi@0 | 568 | TosState state = as_TosState(info.field_type()); |
aoqi@0 | 569 | |
aoqi@0 | 570 | // We need to delay resolving put instructions on final fields |
aoqi@0 | 571 | // until we actually invoke one. This is required so we throw |
aoqi@0 | 572 | // exceptions at the correct place. If we do not resolve completely |
aoqi@0 | 573 | // in the current pass, leaving the put_code set to zero will |
aoqi@0 | 574 | // cause the next put instruction to reresolve. |
aoqi@0 | 575 | Bytecodes::Code put_code = (Bytecodes::Code)0; |
aoqi@0 | 576 | |
aoqi@0 | 577 | // We also need to delay resolving getstatic instructions until the |
aoqi@0 | 578 | // class is intitialized. This is required so that access to the static |
aoqi@0 | 579 | // field will call the initialization function every time until the class |
aoqi@0 | 580 | // is completely initialized ala. in 2.17.5 in JVM Specification. |
aoqi@0 | 581 | InstanceKlass* klass = InstanceKlass::cast(info.field_holder()); |
aoqi@0 | 582 | bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) && |
aoqi@0 | 583 | !klass->is_initialized()); |
aoqi@0 | 584 | Bytecodes::Code get_code = (Bytecodes::Code)0; |
aoqi@0 | 585 | |
aoqi@0 | 586 | if (!uninitialized_static) { |
aoqi@0 | 587 | get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield); |
aoqi@0 | 588 | if (is_put || !info.access_flags().is_final()) { |
aoqi@0 | 589 | put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield); |
aoqi@0 | 590 | } |
aoqi@0 | 591 | } |
aoqi@0 | 592 | |
aoqi@0 | 593 | cache_entry(thread)->set_field( |
aoqi@0 | 594 | get_code, |
aoqi@0 | 595 | put_code, |
aoqi@0 | 596 | info.field_holder(), |
aoqi@0 | 597 | info.index(), |
aoqi@0 | 598 | info.offset(), |
aoqi@0 | 599 | state, |
aoqi@0 | 600 | info.access_flags().is_final(), |
aoqi@0 | 601 | info.access_flags().is_volatile(), |
aoqi@0 | 602 | pool->pool_holder() |
aoqi@0 | 603 | ); |
aoqi@0 | 604 | IRT_END |
aoqi@0 | 605 | |
aoqi@0 | 606 | |
aoqi@0 | 607 | //------------------------------------------------------------------------------------------------------------------------ |
aoqi@0 | 608 | // Synchronization |
aoqi@0 | 609 | // |
aoqi@0 | 610 | // The interpreter's synchronization code is factored out so that it can |
aoqi@0 | 611 | // be shared by method invocation and synchronized blocks. |
aoqi@0 | 612 | //%note synchronization_3 |
aoqi@0 | 613 | |
aoqi@0 | 614 | //%note monitor_1 |
aoqi@0 | 615 | IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem)) |
aoqi@0 | 616 | #ifdef ASSERT |
aoqi@0 | 617 | thread->last_frame().interpreter_frame_verify_monitor(elem); |
aoqi@0 | 618 | #endif |
aoqi@0 | 619 | if (PrintBiasedLockingStatistics) { |
aoqi@0 | 620 | Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); |
aoqi@0 | 621 | } |
aoqi@0 | 622 | Handle h_obj(thread, elem->obj()); |
aoqi@0 | 623 | assert(Universe::heap()->is_in_reserved_or_null(h_obj()), |
aoqi@0 | 624 | "must be NULL or an object"); |
aoqi@0 | 625 | if (UseBiasedLocking) { |
aoqi@0 | 626 | // Retry fast entry if bias is revoked to avoid unnecessary inflation |
aoqi@0 | 627 | ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK); |
aoqi@0 | 628 | } else { |
aoqi@0 | 629 | ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK); |
aoqi@0 | 630 | } |
aoqi@0 | 631 | assert(Universe::heap()->is_in_reserved_or_null(elem->obj()), |
aoqi@0 | 632 | "must be NULL or an object"); |
aoqi@0 | 633 | #ifdef ASSERT |
aoqi@0 | 634 | thread->last_frame().interpreter_frame_verify_monitor(elem); |
aoqi@0 | 635 | #endif |
aoqi@0 | 636 | IRT_END |
aoqi@0 | 637 | |
aoqi@0 | 638 | |
aoqi@0 | 639 | //%note monitor_1 |
aoqi@0 | 640 | IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem)) |
aoqi@0 | 641 | #ifdef ASSERT |
aoqi@0 | 642 | thread->last_frame().interpreter_frame_verify_monitor(elem); |
aoqi@0 | 643 | #endif |
aoqi@0 | 644 | Handle h_obj(thread, elem->obj()); |
aoqi@0 | 645 | assert(Universe::heap()->is_in_reserved_or_null(h_obj()), |
aoqi@0 | 646 | "must be NULL or an object"); |
aoqi@0 | 647 | if (elem == NULL || h_obj()->is_unlocked()) { |
aoqi@0 | 648 | THROW(vmSymbols::java_lang_IllegalMonitorStateException()); |
aoqi@0 | 649 | } |
aoqi@0 | 650 | ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread); |
aoqi@0 | 651 | // Free entry. This must be done here, since a pending exception might be installed on |
aoqi@0 | 652 | // exit. If it is not cleared, the exception handling code will try to unlock the monitor again. |
aoqi@0 | 653 | elem->set_obj(NULL); |
aoqi@0 | 654 | #ifdef ASSERT |
aoqi@0 | 655 | thread->last_frame().interpreter_frame_verify_monitor(elem); |
aoqi@0 | 656 | #endif |
aoqi@0 | 657 | IRT_END |
aoqi@0 | 658 | |
aoqi@0 | 659 | |
aoqi@0 | 660 | IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread)) |
aoqi@0 | 661 | THROW(vmSymbols::java_lang_IllegalMonitorStateException()); |
aoqi@0 | 662 | IRT_END |
aoqi@0 | 663 | |
aoqi@0 | 664 | |
aoqi@0 | 665 | IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread)) |
aoqi@0 | 666 | // Returns an illegal exception to install into the current thread. The |
aoqi@0 | 667 | // pending_exception flag is cleared so normal exception handling does not |
aoqi@0 | 668 | // trigger. Any current installed exception will be overwritten. This |
aoqi@0 | 669 | // method will be called during an exception unwind. |
aoqi@0 | 670 | |
aoqi@0 | 671 | assert(!HAS_PENDING_EXCEPTION, "no pending exception"); |
aoqi@0 | 672 | Handle exception(thread, thread->vm_result()); |
aoqi@0 | 673 | assert(exception() != NULL, "vm result should be set"); |
aoqi@0 | 674 | thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures) |
aoqi@0 | 675 | if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) { |
aoqi@0 | 676 | exception = get_preinitialized_exception( |
aoqi@0 | 677 | SystemDictionary::IllegalMonitorStateException_klass(), |
aoqi@0 | 678 | CATCH); |
aoqi@0 | 679 | } |
aoqi@0 | 680 | thread->set_vm_result(exception()); |
aoqi@0 | 681 | IRT_END |
aoqi@0 | 682 | |
aoqi@0 | 683 | |
aoqi@0 | 684 | //------------------------------------------------------------------------------------------------------------------------ |
aoqi@0 | 685 | // Invokes |
aoqi@0 | 686 | |
aoqi@0 | 687 | IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, Method* method, address bcp)) |
aoqi@0 | 688 | return method->orig_bytecode_at(method->bci_from(bcp)); |
aoqi@0 | 689 | IRT_END |
aoqi@0 | 690 | |
aoqi@0 | 691 | IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code)) |
aoqi@0 | 692 | method->set_orig_bytecode_at(method->bci_from(bcp), new_code); |
aoqi@0 | 693 | IRT_END |
aoqi@0 | 694 | |
aoqi@0 | 695 | IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp)) |
aoqi@0 | 696 | JvmtiExport::post_raw_breakpoint(thread, method, bcp); |
aoqi@0 | 697 | IRT_END |
aoqi@0 | 698 | |
aoqi@0 | 699 | IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) { |
aoqi@0 | 700 | // extract receiver from the outgoing argument list if necessary |
aoqi@0 | 701 | Handle receiver(thread, NULL); |
aoqi@0 | 702 | if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) { |
aoqi@0 | 703 | ResourceMark rm(thread); |
aoqi@0 | 704 | methodHandle m (thread, method(thread)); |
aoqi@0 | 705 | Bytecode_invoke call(m, bci(thread)); |
aoqi@0 | 706 | Symbol* signature = call.signature(); |
aoqi@0 | 707 | receiver = Handle(thread, |
aoqi@0 | 708 | thread->last_frame().interpreter_callee_receiver(signature)); |
aoqi@0 | 709 | assert(Universe::heap()->is_in_reserved_or_null(receiver()), |
aoqi@0 | 710 | "sanity check"); |
aoqi@0 | 711 | assert(receiver.is_null() || |
aoqi@0 | 712 | !Universe::heap()->is_in_reserved(receiver->klass()), |
aoqi@0 | 713 | "sanity check"); |
aoqi@0 | 714 | } |
aoqi@0 | 715 | |
aoqi@0 | 716 | // resolve method |
aoqi@0 | 717 | CallInfo info; |
aoqi@0 | 718 | constantPoolHandle pool(thread, method(thread)->constants()); |
aoqi@0 | 719 | |
aoqi@0 | 720 | { |
aoqi@0 | 721 | JvmtiHideSingleStepping jhss(thread); |
aoqi@0 | 722 | LinkResolver::resolve_invoke(info, receiver, pool, |
aoqi@0 | 723 | get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); |
aoqi@0 | 724 | if (JvmtiExport::can_hotswap_or_post_breakpoint()) { |
aoqi@0 | 725 | int retry_count = 0; |
aoqi@0 | 726 | while (info.resolved_method()->is_old()) { |
aoqi@0 | 727 | // It is very unlikely that method is redefined more than 100 times |
aoqi@0 | 728 | // in the middle of resolve. If it is looping here more than 100 times |
aoqi@0 | 729 | // means then there could be a bug here. |
aoqi@0 | 730 | guarantee((retry_count++ < 100), |
aoqi@0 | 731 | "Could not resolve to latest version of redefined method"); |
aoqi@0 | 732 | // method is redefined in the middle of resolve so re-try. |
aoqi@0 | 733 | LinkResolver::resolve_invoke(info, receiver, pool, |
aoqi@0 | 734 | get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); |
aoqi@0 | 735 | } |
aoqi@0 | 736 | } |
aoqi@0 | 737 | } // end JvmtiHideSingleStepping |
aoqi@0 | 738 | |
aoqi@0 | 739 | // check if link resolution caused cpCache to be updated |
aoqi@0 | 740 | if (already_resolved(thread)) return; |
aoqi@0 | 741 | |
aoqi@0 | 742 | if (bytecode == Bytecodes::_invokeinterface) { |
aoqi@0 | 743 | if (TraceItables && Verbose) { |
aoqi@0 | 744 | ResourceMark rm(thread); |
aoqi@0 | 745 | tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string()); |
aoqi@0 | 746 | } |
aoqi@0 | 747 | } |
aoqi@0 | 748 | #ifdef ASSERT |
aoqi@0 | 749 | if (bytecode == Bytecodes::_invokeinterface) { |
aoqi@0 | 750 | if (info.resolved_method()->method_holder() == |
aoqi@0 | 751 | SystemDictionary::Object_klass()) { |
aoqi@0 | 752 | // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec |
aoqi@0 | 753 | // (see also CallInfo::set_interface for details) |
aoqi@0 | 754 | assert(info.call_kind() == CallInfo::vtable_call || |
aoqi@0 | 755 | info.call_kind() == CallInfo::direct_call, ""); |
aoqi@0 | 756 | methodHandle rm = info.resolved_method(); |
aoqi@0 | 757 | assert(rm->is_final() || info.has_vtable_index(), |
aoqi@0 | 758 | "should have been set already"); |
aoqi@0 | 759 | } else if (!info.resolved_method()->has_itable_index()) { |
aoqi@0 | 760 | // Resolved something like CharSequence.toString. Use vtable not itable. |
aoqi@0 | 761 | assert(info.call_kind() != CallInfo::itable_call, ""); |
aoqi@0 | 762 | } else { |
aoqi@0 | 763 | // Setup itable entry |
aoqi@0 | 764 | assert(info.call_kind() == CallInfo::itable_call, ""); |
aoqi@0 | 765 | int index = info.resolved_method()->itable_index(); |
aoqi@0 | 766 | assert(info.itable_index() == index, ""); |
aoqi@0 | 767 | } |
aoqi@0 | 768 | } else { |
aoqi@0 | 769 | assert(info.call_kind() == CallInfo::direct_call || |
aoqi@0 | 770 | info.call_kind() == CallInfo::vtable_call, ""); |
aoqi@0 | 771 | } |
aoqi@0 | 772 | #endif |
aoqi@0 | 773 | switch (info.call_kind()) { |
aoqi@0 | 774 | case CallInfo::direct_call: |
aoqi@0 | 775 | cache_entry(thread)->set_direct_call( |
aoqi@0 | 776 | bytecode, |
aoqi@0 | 777 | info.resolved_method()); |
aoqi@0 | 778 | break; |
aoqi@0 | 779 | case CallInfo::vtable_call: |
aoqi@0 | 780 | cache_entry(thread)->set_vtable_call( |
aoqi@0 | 781 | bytecode, |
aoqi@0 | 782 | info.resolved_method(), |
aoqi@0 | 783 | info.vtable_index()); |
aoqi@0 | 784 | break; |
aoqi@0 | 785 | case CallInfo::itable_call: |
aoqi@0 | 786 | cache_entry(thread)->set_itable_call( |
aoqi@0 | 787 | bytecode, |
aoqi@0 | 788 | info.resolved_method(), |
aoqi@0 | 789 | info.itable_index()); |
aoqi@0 | 790 | break; |
aoqi@0 | 791 | default: ShouldNotReachHere(); |
aoqi@0 | 792 | } |
aoqi@0 | 793 | } |
aoqi@0 | 794 | IRT_END |
aoqi@0 | 795 | |
aoqi@0 | 796 | |
aoqi@0 | 797 | // First time execution: Resolve symbols, create a permanent MethodType object. |
aoqi@0 | 798 | IRT_ENTRY(void, InterpreterRuntime::resolve_invokehandle(JavaThread* thread)) { |
aoqi@0 | 799 | assert(EnableInvokeDynamic, ""); |
aoqi@0 | 800 | const Bytecodes::Code bytecode = Bytecodes::_invokehandle; |
aoqi@0 | 801 | |
aoqi@0 | 802 | // resolve method |
aoqi@0 | 803 | CallInfo info; |
aoqi@0 | 804 | constantPoolHandle pool(thread, method(thread)->constants()); |
aoqi@0 | 805 | |
aoqi@0 | 806 | { |
aoqi@0 | 807 | JvmtiHideSingleStepping jhss(thread); |
aoqi@0 | 808 | LinkResolver::resolve_invoke(info, Handle(), pool, |
aoqi@0 | 809 | get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); |
aoqi@0 | 810 | } // end JvmtiHideSingleStepping |
aoqi@0 | 811 | |
aoqi@0 | 812 | cache_entry(thread)->set_method_handle(pool, info); |
aoqi@0 | 813 | } |
aoqi@0 | 814 | IRT_END |
aoqi@0 | 815 | |
aoqi@0 | 816 | |
aoqi@0 | 817 | // First time execution: Resolve symbols, create a permanent CallSite object. |
aoqi@0 | 818 | IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) { |
aoqi@0 | 819 | assert(EnableInvokeDynamic, ""); |
aoqi@0 | 820 | const Bytecodes::Code bytecode = Bytecodes::_invokedynamic; |
aoqi@0 | 821 | |
aoqi@0 | 822 | //TO DO: consider passing BCI to Java. |
aoqi@0 | 823 | // int caller_bci = method(thread)->bci_from(bcp(thread)); |
aoqi@0 | 824 | |
aoqi@0 | 825 | // resolve method |
aoqi@0 | 826 | CallInfo info; |
aoqi@0 | 827 | constantPoolHandle pool(thread, method(thread)->constants()); |
aoqi@0 | 828 | int index = get_index_u4(thread, bytecode); |
aoqi@0 | 829 | { |
aoqi@0 | 830 | JvmtiHideSingleStepping jhss(thread); |
aoqi@0 | 831 | LinkResolver::resolve_invoke(info, Handle(), pool, |
aoqi@0 | 832 | index, bytecode, CHECK); |
aoqi@0 | 833 | } // end JvmtiHideSingleStepping |
aoqi@0 | 834 | |
aoqi@0 | 835 | ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index); |
aoqi@0 | 836 | cp_cache_entry->set_dynamic_call(pool, info); |
aoqi@0 | 837 | } |
aoqi@0 | 838 | IRT_END |
aoqi@0 | 839 | |
aoqi@0 | 840 | |
aoqi@0 | 841 | //------------------------------------------------------------------------------------------------------------------------ |
aoqi@0 | 842 | // Miscellaneous |
aoqi@0 | 843 | |
aoqi@0 | 844 | |
aoqi@0 | 845 | nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) { |
aoqi@0 | 846 | nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp); |
aoqi@0 | 847 | assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests"); |
aoqi@0 | 848 | if (branch_bcp != NULL && nm != NULL) { |
aoqi@0 | 849 | // This was a successful request for an OSR nmethod. Because |
aoqi@0 | 850 | // frequency_counter_overflow_inner ends with a safepoint check, |
aoqi@0 | 851 | // nm could have been unloaded so look it up again. It's unsafe |
aoqi@0 | 852 | // to examine nm directly since it might have been freed and used |
aoqi@0 | 853 | // for something else. |
aoqi@0 | 854 | frame fr = thread->last_frame(); |
aoqi@0 | 855 | Method* method = fr.interpreter_frame_method(); |
aoqi@0 | 856 | int bci = method->bci_from(fr.interpreter_frame_bcp()); |
aoqi@0 | 857 | nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false); |
aoqi@0 | 858 | } |
aoqi@0 | 859 | #ifndef PRODUCT |
aoqi@0 | 860 | if (TraceOnStackReplacement) { |
aoqi@0 | 861 | if (nm != NULL) { |
aoqi@0 | 862 | tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", nm->osr_entry()); |
aoqi@0 | 863 | nm->print(); |
aoqi@0 | 864 | } |
aoqi@0 | 865 | } |
aoqi@0 | 866 | #endif |
aoqi@0 | 867 | return nm; |
aoqi@0 | 868 | } |
aoqi@0 | 869 | |
aoqi@0 | 870 | IRT_ENTRY(nmethod*, |
aoqi@0 | 871 | InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp)) |
aoqi@0 | 872 | // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized |
aoqi@0 | 873 | // flag, in case this method triggers classloading which will call into Java. |
aoqi@0 | 874 | UnlockFlagSaver fs(thread); |
aoqi@0 | 875 | |
aoqi@0 | 876 | frame fr = thread->last_frame(); |
aoqi@0 | 877 | assert(fr.is_interpreted_frame(), "must come from interpreter"); |
aoqi@0 | 878 | methodHandle method(thread, fr.interpreter_frame_method()); |
aoqi@0 | 879 | const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci; |
aoqi@0 | 880 | const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci; |
aoqi@0 | 881 | |
aoqi@0 | 882 | assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending"); |
aoqi@0 | 883 | nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread); |
aoqi@0 | 884 | assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions"); |
aoqi@0 | 885 | |
aoqi@0 | 886 | if (osr_nm != NULL) { |
aoqi@0 | 887 | // We may need to do on-stack replacement which requires that no |
aoqi@0 | 888 | // monitors in the activation are biased because their |
aoqi@0 | 889 | // BasicObjectLocks will need to migrate during OSR. Force |
aoqi@0 | 890 | // unbiasing of all monitors in the activation now (even though |
aoqi@0 | 891 | // the OSR nmethod might be invalidated) because we don't have a |
aoqi@0 | 892 | // safepoint opportunity later once the migration begins. |
aoqi@0 | 893 | if (UseBiasedLocking) { |
aoqi@0 | 894 | ResourceMark rm; |
aoqi@0 | 895 | GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>(); |
aoqi@0 | 896 | for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end(); |
aoqi@0 | 897 | kptr < fr.interpreter_frame_monitor_begin(); |
aoqi@0 | 898 | kptr = fr.next_monitor_in_interpreter_frame(kptr) ) { |
aoqi@0 | 899 | if( kptr->obj() != NULL ) { |
aoqi@0 | 900 | objects_to_revoke->append(Handle(THREAD, kptr->obj())); |
aoqi@0 | 901 | } |
aoqi@0 | 902 | } |
aoqi@0 | 903 | BiasedLocking::revoke(objects_to_revoke); |
aoqi@0 | 904 | } |
aoqi@0 | 905 | } |
aoqi@0 | 906 | return osr_nm; |
aoqi@0 | 907 | IRT_END |
aoqi@0 | 908 | |
aoqi@0 | 909 | IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp)) |
aoqi@0 | 910 | assert(ProfileInterpreter, "must be profiling interpreter"); |
aoqi@0 | 911 | int bci = method->bci_from(cur_bcp); |
aoqi@0 | 912 | MethodData* mdo = method->method_data(); |
aoqi@0 | 913 | if (mdo == NULL) return 0; |
aoqi@0 | 914 | return mdo->bci_to_di(bci); |
aoqi@0 | 915 | IRT_END |
aoqi@0 | 916 | |
aoqi@0 | 917 | IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread)) |
aoqi@0 | 918 | // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized |
aoqi@0 | 919 | // flag, in case this method triggers classloading which will call into Java. |
aoqi@0 | 920 | UnlockFlagSaver fs(thread); |
aoqi@0 | 921 | |
aoqi@0 | 922 | assert(ProfileInterpreter, "must be profiling interpreter"); |
aoqi@0 | 923 | frame fr = thread->last_frame(); |
aoqi@0 | 924 | assert(fr.is_interpreted_frame(), "must come from interpreter"); |
aoqi@0 | 925 | methodHandle method(thread, fr.interpreter_frame_method()); |
aoqi@0 | 926 | Method::build_interpreter_method_data(method, THREAD); |
aoqi@0 | 927 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 928 | assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here"); |
aoqi@0 | 929 | CLEAR_PENDING_EXCEPTION; |
aoqi@0 | 930 | // and fall through... |
aoqi@0 | 931 | } |
aoqi@0 | 932 | IRT_END |
aoqi@0 | 933 | |
aoqi@0 | 934 | |
aoqi@0 | 935 | #ifdef ASSERT |
aoqi@0 | 936 | IRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp)) |
aoqi@0 | 937 | assert(ProfileInterpreter, "must be profiling interpreter"); |
aoqi@0 | 938 | |
aoqi@0 | 939 | MethodData* mdo = method->method_data(); |
aoqi@0 | 940 | assert(mdo != NULL, "must not be null"); |
aoqi@0 | 941 | |
aoqi@0 | 942 | int bci = method->bci_from(bcp); |
aoqi@0 | 943 | |
aoqi@0 | 944 | address mdp2 = mdo->bci_to_dp(bci); |
aoqi@0 | 945 | if (mdp != mdp2) { |
aoqi@0 | 946 | ResourceMark rm; |
aoqi@0 | 947 | ResetNoHandleMark rnm; // In a LEAF entry. |
aoqi@0 | 948 | HandleMark hm; |
aoqi@0 | 949 | tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci); |
aoqi@0 | 950 | int current_di = mdo->dp_to_di(mdp); |
aoqi@0 | 951 | int expected_di = mdo->dp_to_di(mdp2); |
aoqi@0 | 952 | tty->print_cr(" actual di %d expected di %d", current_di, expected_di); |
aoqi@0 | 953 | int expected_approx_bci = mdo->data_at(expected_di)->bci(); |
aoqi@0 | 954 | int approx_bci = -1; |
aoqi@0 | 955 | if (current_di >= 0) { |
aoqi@0 | 956 | approx_bci = mdo->data_at(current_di)->bci(); |
aoqi@0 | 957 | } |
aoqi@0 | 958 | tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci); |
aoqi@0 | 959 | mdo->print_on(tty); |
aoqi@0 | 960 | method->print_codes(); |
aoqi@0 | 961 | } |
aoqi@0 | 962 | assert(mdp == mdp2, "wrong mdp"); |
aoqi@0 | 963 | IRT_END |
aoqi@0 | 964 | #endif // ASSERT |
aoqi@0 | 965 | |
aoqi@0 | 966 | IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci)) |
aoqi@0 | 967 | assert(ProfileInterpreter, "must be profiling interpreter"); |
aoqi@0 | 968 | ResourceMark rm(thread); |
aoqi@0 | 969 | HandleMark hm(thread); |
aoqi@0 | 970 | frame fr = thread->last_frame(); |
aoqi@0 | 971 | assert(fr.is_interpreted_frame(), "must come from interpreter"); |
aoqi@0 | 972 | MethodData* h_mdo = fr.interpreter_frame_method()->method_data(); |
aoqi@0 | 973 | |
aoqi@0 | 974 | // Grab a lock to ensure atomic access to setting the return bci and |
aoqi@0 | 975 | // the displacement. This can block and GC, invalidating all naked oops. |
aoqi@0 | 976 | MutexLocker ml(RetData_lock); |
aoqi@0 | 977 | |
aoqi@0 | 978 | // ProfileData is essentially a wrapper around a derived oop, so we |
aoqi@0 | 979 | // need to take the lock before making any ProfileData structures. |
aoqi@0 | 980 | ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp())); |
aoqi@0 | 981 | RetData* rdata = data->as_RetData(); |
aoqi@0 | 982 | address new_mdp = rdata->fixup_ret(return_bci, h_mdo); |
aoqi@0 | 983 | fr.interpreter_frame_set_mdp(new_mdp); |
aoqi@0 | 984 | IRT_END |
aoqi@0 | 985 | |
aoqi@0 | 986 | IRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* thread, Method* m)) |
aoqi@0 | 987 | MethodCounters* mcs = Method::build_method_counters(m, thread); |
aoqi@0 | 988 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 989 | assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here"); |
aoqi@0 | 990 | CLEAR_PENDING_EXCEPTION; |
aoqi@0 | 991 | } |
aoqi@0 | 992 | return mcs; |
aoqi@0 | 993 | IRT_END |
aoqi@0 | 994 | |
aoqi@0 | 995 | |
aoqi@0 | 996 | IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread)) |
aoqi@0 | 997 | // We used to need an explict preserve_arguments here for invoke bytecodes. However, |
aoqi@0 | 998 | // stack traversal automatically takes care of preserving arguments for invoke, so |
aoqi@0 | 999 | // this is no longer needed. |
aoqi@0 | 1000 | |
aoqi@0 | 1001 | // IRT_END does an implicit safepoint check, hence we are guaranteed to block |
aoqi@0 | 1002 | // if this is called during a safepoint |
aoqi@0 | 1003 | |
aoqi@0 | 1004 | if (JvmtiExport::should_post_single_step()) { |
aoqi@0 | 1005 | // We are called during regular safepoints and when the VM is |
aoqi@0 | 1006 | // single stepping. If any thread is marked for single stepping, |
aoqi@0 | 1007 | // then we may have JVMTI work to do. |
aoqi@0 | 1008 | JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread)); |
aoqi@0 | 1009 | } |
aoqi@0 | 1010 | IRT_END |
aoqi@0 | 1011 | |
aoqi@0 | 1012 | IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj, |
aoqi@0 | 1013 | ConstantPoolCacheEntry *cp_entry)) |
aoqi@0 | 1014 | |
aoqi@0 | 1015 | // check the access_flags for the field in the klass |
aoqi@0 | 1016 | |
aoqi@0 | 1017 | InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass()); |
aoqi@0 | 1018 | int index = cp_entry->field_index(); |
aoqi@0 | 1019 | if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return; |
aoqi@0 | 1020 | |
aoqi@0 | 1021 | switch(cp_entry->flag_state()) { |
aoqi@0 | 1022 | case btos: // fall through |
kevinw@8370 | 1023 | case ztos: // fall through |
aoqi@0 | 1024 | case ctos: // fall through |
aoqi@0 | 1025 | case stos: // fall through |
aoqi@0 | 1026 | case itos: // fall through |
aoqi@0 | 1027 | case ftos: // fall through |
aoqi@0 | 1028 | case ltos: // fall through |
aoqi@0 | 1029 | case dtos: // fall through |
aoqi@0 | 1030 | case atos: break; |
aoqi@0 | 1031 | default: ShouldNotReachHere(); return; |
aoqi@0 | 1032 | } |
aoqi@0 | 1033 | bool is_static = (obj == NULL); |
aoqi@0 | 1034 | HandleMark hm(thread); |
aoqi@0 | 1035 | |
aoqi@0 | 1036 | Handle h_obj; |
aoqi@0 | 1037 | if (!is_static) { |
aoqi@0 | 1038 | // non-static field accessors have an object, but we need a handle |
aoqi@0 | 1039 | h_obj = Handle(thread, obj); |
aoqi@0 | 1040 | } |
aoqi@0 | 1041 | instanceKlassHandle h_cp_entry_f1(thread, (Klass*)cp_entry->f1_as_klass()); |
aoqi@0 | 1042 | jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2_as_index(), is_static); |
aoqi@0 | 1043 | JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid); |
aoqi@0 | 1044 | IRT_END |
aoqi@0 | 1045 | |
aoqi@0 | 1046 | IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread, |
aoqi@0 | 1047 | oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value)) |
aoqi@0 | 1048 | |
aoqi@0 | 1049 | Klass* k = (Klass*)cp_entry->f1_as_klass(); |
aoqi@0 | 1050 | |
aoqi@0 | 1051 | // check the access_flags for the field in the klass |
aoqi@0 | 1052 | InstanceKlass* ik = InstanceKlass::cast(k); |
aoqi@0 | 1053 | int index = cp_entry->field_index(); |
aoqi@0 | 1054 | // bail out if field modifications are not watched |
aoqi@0 | 1055 | if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return; |
aoqi@0 | 1056 | |
aoqi@0 | 1057 | char sig_type = '\0'; |
aoqi@0 | 1058 | |
aoqi@0 | 1059 | switch(cp_entry->flag_state()) { |
kevinw@8368 | 1060 | case btos: sig_type = 'B'; break; |
kevinw@8368 | 1061 | case ztos: sig_type = 'Z'; break; |
aoqi@0 | 1062 | case ctos: sig_type = 'C'; break; |
aoqi@0 | 1063 | case stos: sig_type = 'S'; break; |
aoqi@0 | 1064 | case itos: sig_type = 'I'; break; |
aoqi@0 | 1065 | case ftos: sig_type = 'F'; break; |
aoqi@0 | 1066 | case atos: sig_type = 'L'; break; |
aoqi@0 | 1067 | case ltos: sig_type = 'J'; break; |
aoqi@0 | 1068 | case dtos: sig_type = 'D'; break; |
aoqi@0 | 1069 | default: ShouldNotReachHere(); return; |
aoqi@0 | 1070 | } |
aoqi@0 | 1071 | bool is_static = (obj == NULL); |
aoqi@0 | 1072 | |
aoqi@0 | 1073 | HandleMark hm(thread); |
aoqi@0 | 1074 | instanceKlassHandle h_klass(thread, k); |
aoqi@0 | 1075 | jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2_as_index(), is_static); |
aoqi@0 | 1076 | jvalue fvalue; |
aoqi@0 | 1077 | #ifdef _LP64 |
aoqi@0 | 1078 | fvalue = *value; |
aoqi@0 | 1079 | #else |
aoqi@0 | 1080 | // Long/double values are stored unaligned and also noncontiguously with |
aoqi@0 | 1081 | // tagged stacks. We can't just do a simple assignment even in the non- |
aoqi@0 | 1082 | // J/D cases because a C++ compiler is allowed to assume that a jvalue is |
aoqi@0 | 1083 | // 8-byte aligned, and interpreter stack slots are only 4-byte aligned. |
aoqi@0 | 1084 | // We assume that the two halves of longs/doubles are stored in interpreter |
aoqi@0 | 1085 | // stack slots in platform-endian order. |
aoqi@0 | 1086 | jlong_accessor u; |
aoqi@0 | 1087 | jint* newval = (jint*)value; |
aoqi@0 | 1088 | u.words[0] = newval[0]; |
aoqi@0 | 1089 | u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag |
aoqi@0 | 1090 | fvalue.j = u.long_value; |
aoqi@0 | 1091 | #endif // _LP64 |
aoqi@0 | 1092 | |
aoqi@0 | 1093 | Handle h_obj; |
aoqi@0 | 1094 | if (!is_static) { |
aoqi@0 | 1095 | // non-static field accessors have an object, but we need a handle |
aoqi@0 | 1096 | h_obj = Handle(thread, obj); |
aoqi@0 | 1097 | } |
aoqi@0 | 1098 | |
aoqi@0 | 1099 | JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj, |
aoqi@0 | 1100 | fid, sig_type, &fvalue); |
aoqi@0 | 1101 | IRT_END |
aoqi@0 | 1102 | |
aoqi@0 | 1103 | IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread)) |
aoqi@0 | 1104 | JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread)); |
aoqi@0 | 1105 | IRT_END |
aoqi@0 | 1106 | |
aoqi@0 | 1107 | |
aoqi@0 | 1108 | IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread)) |
aoqi@0 | 1109 | JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread)); |
aoqi@0 | 1110 | IRT_END |
aoqi@0 | 1111 | |
aoqi@0 | 1112 | IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc)) |
aoqi@0 | 1113 | { |
aoqi@0 | 1114 | return (Interpreter::contains(pc) ? 1 : 0); |
aoqi@0 | 1115 | } |
aoqi@0 | 1116 | IRT_END |
aoqi@0 | 1117 | |
aoqi@0 | 1118 | |
aoqi@0 | 1119 | // Implementation of SignatureHandlerLibrary |
aoqi@0 | 1120 | |
aoqi@0 | 1121 | address SignatureHandlerLibrary::set_handler_blob() { |
aoqi@0 | 1122 | BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size); |
aoqi@0 | 1123 | if (handler_blob == NULL) { |
aoqi@0 | 1124 | return NULL; |
aoqi@0 | 1125 | } |
aoqi@0 | 1126 | address handler = handler_blob->code_begin(); |
aoqi@0 | 1127 | _handler_blob = handler_blob; |
aoqi@0 | 1128 | _handler = handler; |
aoqi@0 | 1129 | return handler; |
aoqi@0 | 1130 | } |
aoqi@0 | 1131 | |
aoqi@0 | 1132 | void SignatureHandlerLibrary::initialize() { |
aoqi@0 | 1133 | if (_fingerprints != NULL) { |
aoqi@0 | 1134 | return; |
aoqi@0 | 1135 | } |
aoqi@0 | 1136 | if (set_handler_blob() == NULL) { |
aoqi@0 | 1137 | vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers"); |
aoqi@0 | 1138 | } |
aoqi@0 | 1139 | |
aoqi@0 | 1140 | BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer", |
aoqi@0 | 1141 | SignatureHandlerLibrary::buffer_size); |
aoqi@0 | 1142 | _buffer = bb->code_begin(); |
aoqi@0 | 1143 | |
aoqi@0 | 1144 | _fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, true); |
aoqi@0 | 1145 | _handlers = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, true); |
aoqi@0 | 1146 | } |
aoqi@0 | 1147 | |
aoqi@0 | 1148 | address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) { |
aoqi@0 | 1149 | address handler = _handler; |
aoqi@0 | 1150 | int insts_size = buffer->pure_insts_size(); |
aoqi@0 | 1151 | if (handler + insts_size > _handler_blob->code_end()) { |
aoqi@0 | 1152 | // get a new handler blob |
aoqi@0 | 1153 | handler = set_handler_blob(); |
aoqi@0 | 1154 | } |
aoqi@0 | 1155 | if (handler != NULL) { |
aoqi@0 | 1156 | memcpy(handler, buffer->insts_begin(), insts_size); |
aoqi@0 | 1157 | pd_set_handler(handler); |
aoqi@0 | 1158 | ICache::invalidate_range(handler, insts_size); |
aoqi@0 | 1159 | _handler = handler + insts_size; |
aoqi@0 | 1160 | } |
aoqi@0 | 1161 | return handler; |
aoqi@0 | 1162 | } |
aoqi@0 | 1163 | |
aoqi@0 | 1164 | void SignatureHandlerLibrary::add(methodHandle method) { |
aoqi@0 | 1165 | if (method->signature_handler() == NULL) { |
aoqi@0 | 1166 | // use slow signature handler if we can't do better |
aoqi@0 | 1167 | int handler_index = -1; |
aoqi@0 | 1168 | // check if we can use customized (fast) signature handler |
aoqi@0 | 1169 | if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) { |
aoqi@0 | 1170 | // use customized signature handler |
aoqi@0 | 1171 | MutexLocker mu(SignatureHandlerLibrary_lock); |
aoqi@0 | 1172 | // make sure data structure is initialized |
aoqi@0 | 1173 | initialize(); |
aoqi@0 | 1174 | // lookup method signature's fingerprint |
aoqi@0 | 1175 | uint64_t fingerprint = Fingerprinter(method).fingerprint(); |
aoqi@0 | 1176 | handler_index = _fingerprints->find(fingerprint); |
aoqi@0 | 1177 | // create handler if necessary |
aoqi@0 | 1178 | if (handler_index < 0) { |
aoqi@0 | 1179 | ResourceMark rm; |
aoqi@0 | 1180 | ptrdiff_t align_offset = (address) |
aoqi@0 | 1181 | round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer; |
aoqi@0 | 1182 | CodeBuffer buffer((address)(_buffer + align_offset), |
aoqi@0 | 1183 | SignatureHandlerLibrary::buffer_size - align_offset); |
aoqi@0 | 1184 | InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint); |
aoqi@0 | 1185 | // copy into code heap |
aoqi@0 | 1186 | address handler = set_handler(&buffer); |
aoqi@0 | 1187 | if (handler == NULL) { |
aoqi@0 | 1188 | // use slow signature handler |
aoqi@0 | 1189 | } else { |
aoqi@0 | 1190 | // debugging suppport |
aoqi@0 | 1191 | if (PrintSignatureHandlers) { |
aoqi@0 | 1192 | tty->cr(); |
aoqi@0 | 1193 | tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)", |
aoqi@0 | 1194 | _handlers->length(), |
aoqi@0 | 1195 | (method->is_static() ? "static" : "receiver"), |
aoqi@0 | 1196 | method->name_and_sig_as_C_string(), |
aoqi@0 | 1197 | fingerprint, |
aoqi@0 | 1198 | buffer.insts_size()); |
aoqi@0 | 1199 | Disassembler::decode(handler, handler + buffer.insts_size()); |
aoqi@0 | 1200 | #ifndef PRODUCT |
aoqi@0 | 1201 | tty->print_cr(" --- associated result handler ---"); |
aoqi@0 | 1202 | address rh_begin = Interpreter::result_handler(method()->result_type()); |
aoqi@0 | 1203 | address rh_end = rh_begin; |
aoqi@0 | 1204 | while (*(int*)rh_end != 0) { |
aoqi@0 | 1205 | rh_end += sizeof(int); |
aoqi@0 | 1206 | } |
aoqi@0 | 1207 | Disassembler::decode(rh_begin, rh_end); |
aoqi@0 | 1208 | #endif |
aoqi@0 | 1209 | } |
aoqi@0 | 1210 | // add handler to library |
aoqi@0 | 1211 | _fingerprints->append(fingerprint); |
aoqi@0 | 1212 | _handlers->append(handler); |
aoqi@0 | 1213 | // set handler index |
aoqi@0 | 1214 | assert(_fingerprints->length() == _handlers->length(), "sanity check"); |
aoqi@0 | 1215 | handler_index = _fingerprints->length() - 1; |
aoqi@0 | 1216 | } |
aoqi@0 | 1217 | } |
aoqi@0 | 1218 | // Set handler under SignatureHandlerLibrary_lock |
aoqi@0 | 1219 | if (handler_index < 0) { |
aoqi@0 | 1220 | // use generic signature handler |
aoqi@0 | 1221 | method->set_signature_handler(Interpreter::slow_signature_handler()); |
aoqi@0 | 1222 | } else { |
aoqi@0 | 1223 | // set handler |
aoqi@0 | 1224 | method->set_signature_handler(_handlers->at(handler_index)); |
aoqi@0 | 1225 | } |
aoqi@0 | 1226 | } else { |
aoqi@0 | 1227 | CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); |
aoqi@0 | 1228 | // use generic signature handler |
aoqi@0 | 1229 | method->set_signature_handler(Interpreter::slow_signature_handler()); |
aoqi@0 | 1230 | } |
aoqi@0 | 1231 | } |
aoqi@0 | 1232 | #ifdef ASSERT |
aoqi@0 | 1233 | int handler_index = -1; |
aoqi@0 | 1234 | int fingerprint_index = -2; |
aoqi@0 | 1235 | { |
aoqi@0 | 1236 | // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized |
aoqi@0 | 1237 | // in any way if accessed from multiple threads. To avoid races with another |
aoqi@0 | 1238 | // thread which may change the arrays in the above, mutex protected block, we |
aoqi@0 | 1239 | // have to protect this read access here with the same mutex as well! |
aoqi@0 | 1240 | MutexLocker mu(SignatureHandlerLibrary_lock); |
aoqi@0 | 1241 | if (_handlers != NULL) { |
aoqi@0 | 1242 | handler_index = _handlers->find(method->signature_handler()); |
aoqi@0 | 1243 | fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint()); |
aoqi@0 | 1244 | } |
aoqi@0 | 1245 | } |
aoqi@0 | 1246 | assert(method->signature_handler() == Interpreter::slow_signature_handler() || |
aoqi@0 | 1247 | handler_index == fingerprint_index, "sanity check"); |
aoqi@0 | 1248 | #endif // ASSERT |
aoqi@0 | 1249 | } |
aoqi@0 | 1250 | |
aoqi@0 | 1251 | |
aoqi@0 | 1252 | BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL; |
aoqi@0 | 1253 | address SignatureHandlerLibrary::_handler = NULL; |
aoqi@0 | 1254 | GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL; |
aoqi@0 | 1255 | GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL; |
aoqi@0 | 1256 | address SignatureHandlerLibrary::_buffer = NULL; |
aoqi@0 | 1257 | |
aoqi@0 | 1258 | |
aoqi@0 | 1259 | IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, Method* method)) |
aoqi@0 | 1260 | methodHandle m(thread, method); |
aoqi@0 | 1261 | assert(m->is_native(), "sanity check"); |
aoqi@0 | 1262 | // lookup native function entry point if it doesn't exist |
aoqi@0 | 1263 | bool in_base_library; |
aoqi@0 | 1264 | if (!m->has_native_function()) { |
aoqi@0 | 1265 | NativeLookup::lookup(m, in_base_library, CHECK); |
aoqi@0 | 1266 | } |
aoqi@0 | 1267 | // make sure signature handler is installed |
aoqi@0 | 1268 | SignatureHandlerLibrary::add(m); |
aoqi@0 | 1269 | // The interpreter entry point checks the signature handler first, |
aoqi@0 | 1270 | // before trying to fetch the native entry point and klass mirror. |
aoqi@0 | 1271 | // We must set the signature handler last, so that multiple processors |
aoqi@0 | 1272 | // preparing the same method will be sure to see non-null entry & mirror. |
aoqi@0 | 1273 | IRT_END |
aoqi@0 | 1274 | |
aoqi@1 | 1275 | #if defined(IA32) || defined(AMD64) || defined(ARM) || defined(MIPS64) |
aoqi@0 | 1276 | IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address)) |
aoqi@0 | 1277 | if (src_address == dest_address) { |
aoqi@0 | 1278 | return; |
aoqi@0 | 1279 | } |
aoqi@0 | 1280 | ResetNoHandleMark rnm; // In a LEAF entry. |
aoqi@0 | 1281 | HandleMark hm; |
aoqi@0 | 1282 | ResourceMark rm; |
aoqi@0 | 1283 | frame fr = thread->last_frame(); |
aoqi@0 | 1284 | assert(fr.is_interpreted_frame(), ""); |
aoqi@0 | 1285 | jint bci = fr.interpreter_frame_bci(); |
aoqi@0 | 1286 | methodHandle mh(thread, fr.interpreter_frame_method()); |
aoqi@0 | 1287 | Bytecode_invoke invoke(mh, bci); |
aoqi@0 | 1288 | ArgumentSizeComputer asc(invoke.signature()); |
aoqi@0 | 1289 | int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver |
aoqi@0 | 1290 | Copy::conjoint_jbytes(src_address, dest_address, |
aoqi@0 | 1291 | size_of_arguments * Interpreter::stackElementSize); |
aoqi@0 | 1292 | IRT_END |
aoqi@0 | 1293 | #endif |
aoqi@0 | 1294 | |
aoqi@0 | 1295 | #if INCLUDE_JVMTI |
aoqi@0 | 1296 | // This is a support of the JVMTI PopFrame interface. |
aoqi@0 | 1297 | // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument |
aoqi@0 | 1298 | // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters. |
vlivanov@7181 | 1299 | // The member_name argument is a saved reference (in local#0) to the member_name. |
vlivanov@7181 | 1300 | // For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle. |
vlivanov@7181 | 1301 | // FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated. |
vlivanov@7181 | 1302 | IRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* thread, address member_name, |
aoqi@0 | 1303 | Method* method, address bcp)) |
aoqi@0 | 1304 | Bytecodes::Code code = Bytecodes::code_at(method, bcp); |
aoqi@0 | 1305 | if (code != Bytecodes::_invokestatic) { |
aoqi@0 | 1306 | return; |
aoqi@0 | 1307 | } |
aoqi@0 | 1308 | ConstantPool* cpool = method->constants(); |
aoqi@0 | 1309 | int cp_index = Bytes::get_native_u2(bcp + 1) + ConstantPool::CPCACHE_INDEX_TAG; |
aoqi@0 | 1310 | Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index)); |
aoqi@0 | 1311 | Symbol* mname = cpool->name_ref_at(cp_index); |
aoqi@0 | 1312 | |
aoqi@0 | 1313 | if (MethodHandles::has_member_arg(cname, mname)) { |
vlivanov@7181 | 1314 | oop member_name_oop = (oop) member_name; |
vlivanov@7181 | 1315 | if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) { |
vlivanov@7181 | 1316 | // FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated. |
vlivanov@7181 | 1317 | member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop); |
vlivanov@7181 | 1318 | } |
vlivanov@7181 | 1319 | thread->set_vm_result(member_name_oop); |
sspitsyn@7803 | 1320 | } else { |
sspitsyn@7803 | 1321 | thread->set_vm_result(NULL); |
aoqi@0 | 1322 | } |
aoqi@0 | 1323 | IRT_END |
aoqi@0 | 1324 | #endif // INCLUDE_JVMTI |