src/share/vm/c1/c1_Runtime1.cpp

Mon, 14 Mar 2016 12:35:48 +0300

author
vlivanov
date
Mon, 14 Mar 2016 12:35:48 +0300
changeset 8419
65a0107d52ed
parent 7598
ddce0b7cee93
child 8604
04d83ba48607
child 9305
278ac6d2b59e
permissions
-rw-r--r--

8141420: Compiler runtime entries don't hold Klass* from being GCed
Reviewed-by: kvn, coleenp

duke@435 1 /*
dlong@7598 2 * Copyright (c) 1999, 2015, 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 "asm/codeBuffer.hpp"
stefank@2314 27 #include "c1/c1_CodeStubs.hpp"
stefank@2314 28 #include "c1/c1_Defs.hpp"
stefank@2314 29 #include "c1/c1_FrameMap.hpp"
stefank@2314 30 #include "c1/c1_LIRAssembler.hpp"
stefank@2314 31 #include "c1/c1_MacroAssembler.hpp"
stefank@2314 32 #include "c1/c1_Runtime1.hpp"
stefank@2314 33 #include "classfile/systemDictionary.hpp"
stefank@2314 34 #include "classfile/vmSymbols.hpp"
stefank@2314 35 #include "code/codeBlob.hpp"
stefank@2314 36 #include "code/compiledIC.hpp"
stefank@2314 37 #include "code/pcDesc.hpp"
stefank@2314 38 #include "code/scopeDesc.hpp"
stefank@2314 39 #include "code/vtableStubs.hpp"
stefank@2314 40 #include "compiler/disassembler.hpp"
stefank@2314 41 #include "gc_interface/collectedHeap.hpp"
stefank@2314 42 #include "interpreter/bytecode.hpp"
stefank@2314 43 #include "interpreter/interpreter.hpp"
stefank@2314 44 #include "memory/allocation.inline.hpp"
stefank@2314 45 #include "memory/barrierSet.hpp"
stefank@2314 46 #include "memory/oopFactory.hpp"
stefank@2314 47 #include "memory/resourceArea.hpp"
stefank@2314 48 #include "oops/objArrayKlass.hpp"
stefank@2314 49 #include "oops/oop.inline.hpp"
stefank@2314 50 #include "runtime/biasedLocking.hpp"
stefank@2314 51 #include "runtime/compilationPolicy.hpp"
stefank@2314 52 #include "runtime/interfaceSupport.hpp"
stefank@2314 53 #include "runtime/javaCalls.hpp"
stefank@2314 54 #include "runtime/sharedRuntime.hpp"
stefank@2314 55 #include "runtime/threadCritical.hpp"
stefank@2314 56 #include "runtime/vframe.hpp"
stefank@2314 57 #include "runtime/vframeArray.hpp"
stefank@2314 58 #include "utilities/copy.hpp"
stefank@2314 59 #include "utilities/events.hpp"
duke@435 60
duke@435 61
duke@435 62 // Implementation of StubAssembler
duke@435 63
duke@435 64 StubAssembler::StubAssembler(CodeBuffer* code, const char * name, int stub_id) : C1_MacroAssembler(code) {
duke@435 65 _name = name;
duke@435 66 _must_gc_arguments = false;
duke@435 67 _frame_size = no_frame_size;
duke@435 68 _num_rt_args = 0;
duke@435 69 _stub_id = stub_id;
duke@435 70 }
duke@435 71
duke@435 72
duke@435 73 void StubAssembler::set_info(const char* name, bool must_gc_arguments) {
duke@435 74 _name = name;
duke@435 75 _must_gc_arguments = must_gc_arguments;
duke@435 76 }
duke@435 77
duke@435 78
duke@435 79 void StubAssembler::set_frame_size(int size) {
duke@435 80 if (_frame_size == no_frame_size) {
duke@435 81 _frame_size = size;
duke@435 82 }
duke@435 83 assert(_frame_size == size, "can't change the frame size");
duke@435 84 }
duke@435 85
duke@435 86
duke@435 87 void StubAssembler::set_num_rt_args(int args) {
duke@435 88 if (_num_rt_args == 0) {
duke@435 89 _num_rt_args = args;
duke@435 90 }
duke@435 91 assert(_num_rt_args == args, "can't change the number of args");
duke@435 92 }
duke@435 93
duke@435 94 // Implementation of Runtime1
duke@435 95
duke@435 96 CodeBlob* Runtime1::_blobs[Runtime1::number_of_ids];
duke@435 97 const char *Runtime1::_blob_names[] = {
duke@435 98 RUNTIME1_STUBS(STUB_NAME, LAST_STUB_NAME)
duke@435 99 };
duke@435 100
duke@435 101 #ifndef PRODUCT
duke@435 102 // statistics
duke@435 103 int Runtime1::_generic_arraycopy_cnt = 0;
duke@435 104 int Runtime1::_primitive_arraycopy_cnt = 0;
duke@435 105 int Runtime1::_oop_arraycopy_cnt = 0;
roland@2728 106 int Runtime1::_generic_arraycopystub_cnt = 0;
duke@435 107 int Runtime1::_arraycopy_slowcase_cnt = 0;
roland@2728 108 int Runtime1::_arraycopy_checkcast_cnt = 0;
roland@2728 109 int Runtime1::_arraycopy_checkcast_attempt_cnt = 0;
duke@435 110 int Runtime1::_new_type_array_slowcase_cnt = 0;
duke@435 111 int Runtime1::_new_object_array_slowcase_cnt = 0;
duke@435 112 int Runtime1::_new_instance_slowcase_cnt = 0;
duke@435 113 int Runtime1::_new_multi_array_slowcase_cnt = 0;
duke@435 114 int Runtime1::_monitorenter_slowcase_cnt = 0;
duke@435 115 int Runtime1::_monitorexit_slowcase_cnt = 0;
duke@435 116 int Runtime1::_patch_code_slowcase_cnt = 0;
duke@435 117 int Runtime1::_throw_range_check_exception_count = 0;
duke@435 118 int Runtime1::_throw_index_exception_count = 0;
duke@435 119 int Runtime1::_throw_div0_exception_count = 0;
duke@435 120 int Runtime1::_throw_null_pointer_exception_count = 0;
duke@435 121 int Runtime1::_throw_class_cast_exception_count = 0;
duke@435 122 int Runtime1::_throw_incompatible_class_change_error_count = 0;
duke@435 123 int Runtime1::_throw_array_store_exception_count = 0;
duke@435 124 int Runtime1::_throw_count = 0;
roland@2728 125
roland@2728 126 static int _byte_arraycopy_cnt = 0;
roland@2728 127 static int _short_arraycopy_cnt = 0;
roland@2728 128 static int _int_arraycopy_cnt = 0;
roland@2728 129 static int _long_arraycopy_cnt = 0;
roland@2728 130 static int _oop_arraycopy_cnt = 0;
roland@2728 131
roland@2728 132 address Runtime1::arraycopy_count_address(BasicType type) {
roland@2728 133 switch (type) {
roland@2728 134 case T_BOOLEAN:
roland@2728 135 case T_BYTE: return (address)&_byte_arraycopy_cnt;
roland@2728 136 case T_CHAR:
roland@2728 137 case T_SHORT: return (address)&_short_arraycopy_cnt;
roland@2728 138 case T_FLOAT:
roland@2728 139 case T_INT: return (address)&_int_arraycopy_cnt;
roland@2728 140 case T_DOUBLE:
roland@2728 141 case T_LONG: return (address)&_long_arraycopy_cnt;
roland@2728 142 case T_ARRAY:
roland@2728 143 case T_OBJECT: return (address)&_oop_arraycopy_cnt;
roland@2728 144 default:
roland@2728 145 ShouldNotReachHere();
roland@2728 146 return NULL;
roland@2728 147 }
roland@2728 148 }
roland@2728 149
roland@2728 150
duke@435 151 #endif
duke@435 152
duke@435 153 // Simple helper to see if the caller of a runtime stub which
duke@435 154 // entered the VM has been deoptimized
duke@435 155
duke@435 156 static bool caller_is_deopted() {
duke@435 157 JavaThread* thread = JavaThread::current();
duke@435 158 RegisterMap reg_map(thread, false);
duke@435 159 frame runtime_frame = thread->last_frame();
duke@435 160 frame caller_frame = runtime_frame.sender(&reg_map);
duke@435 161 assert(caller_frame.is_compiled_frame(), "must be compiled");
duke@435 162 return caller_frame.is_deoptimized_frame();
duke@435 163 }
duke@435 164
duke@435 165 // Stress deoptimization
duke@435 166 static void deopt_caller() {
duke@435 167 if ( !caller_is_deopted()) {
duke@435 168 JavaThread* thread = JavaThread::current();
duke@435 169 RegisterMap reg_map(thread, false);
duke@435 170 frame runtime_frame = thread->last_frame();
duke@435 171 frame caller_frame = runtime_frame.sender(&reg_map);
dcubed@1648 172 Deoptimization::deoptimize_frame(thread, caller_frame.id());
duke@435 173 assert(caller_is_deopted(), "Must be deoptimized");
duke@435 174 }
duke@435 175 }
duke@435 176
duke@435 177
iveresov@1939 178 void Runtime1::generate_blob_for(BufferBlob* buffer_blob, StubID id) {
duke@435 179 assert(0 <= id && id < number_of_ids, "illegal stub id");
duke@435 180 ResourceMark rm;
duke@435 181 // create code buffer for code storage
twisti@2103 182 CodeBuffer code(buffer_blob);
duke@435 183
iveresov@1939 184 Compilation::setup_code_buffer(&code, 0);
duke@435 185
duke@435 186 // create assembler for code generation
duke@435 187 StubAssembler* sasm = new StubAssembler(&code, name_for(id), id);
duke@435 188 // generate code for runtime stub
duke@435 189 OopMapSet* oop_maps;
duke@435 190 oop_maps = generate_code_for(id, sasm);
duke@435 191 assert(oop_maps == NULL || sasm->frame_size() != no_frame_size,
duke@435 192 "if stub has an oop map it must have a valid frame size");
duke@435 193
duke@435 194 #ifdef ASSERT
duke@435 195 // Make sure that stubs that need oopmaps have them
duke@435 196 switch (id) {
duke@435 197 // These stubs don't need to have an oopmap
duke@435 198 case dtrace_object_alloc_id:
ysr@777 199 case g1_pre_barrier_slow_id:
ysr@777 200 case g1_post_barrier_slow_id:
duke@435 201 case slow_subtype_check_id:
duke@435 202 case fpu2long_stub_id:
duke@435 203 case unwind_exception_id:
iveresov@2138 204 case counter_overflow_id:
bobv@2036 205 #if defined(SPARC) || defined(PPC)
duke@435 206 case handle_exception_nofpu_id: // Unused on sparc
duke@435 207 #endif
duke@435 208 break;
duke@435 209
duke@435 210 // All other stubs should have oopmaps
duke@435 211 default:
duke@435 212 assert(oop_maps != NULL, "must have an oopmap");
duke@435 213 }
duke@435 214 #endif
duke@435 215
duke@435 216 // align so printing shows nop's instead of random code at the end (SimpleStubs are aligned)
duke@435 217 sasm->align(BytesPerWord);
duke@435 218 // make sure all code is in code buffer
duke@435 219 sasm->flush();
duke@435 220 // create blob - distinguish a few special cases
duke@435 221 CodeBlob* blob = RuntimeStub::new_runtime_stub(name_for(id),
duke@435 222 &code,
duke@435 223 CodeOffsets::frame_never_safe,
duke@435 224 sasm->frame_size(),
duke@435 225 oop_maps,
duke@435 226 sasm->must_gc_arguments());
duke@435 227 // install blob
duke@435 228 assert(blob != NULL, "blob must exist");
duke@435 229 _blobs[id] = blob;
duke@435 230 }
duke@435 231
duke@435 232
iveresov@1939 233 void Runtime1::initialize(BufferBlob* blob) {
iveresov@1939 234 // platform-dependent initialization
iveresov@1939 235 initialize_pd();
iveresov@1939 236 // generate stubs
iveresov@1939 237 for (int id = 0; id < number_of_ids; id++) generate_blob_for(blob, (StubID)id);
iveresov@1939 238 // printing
duke@435 239 #ifndef PRODUCT
iveresov@1939 240 if (PrintSimpleStubs) {
iveresov@1939 241 ResourceMark rm;
iveresov@1939 242 for (int id = 0; id < number_of_ids; id++) {
iveresov@1939 243 _blobs[id]->print();
iveresov@1939 244 if (_blobs[id]->oop_maps() != NULL) {
iveresov@1939 245 _blobs[id]->oop_maps()->print();
duke@435 246 }
duke@435 247 }
iveresov@1939 248 }
duke@435 249 #endif
duke@435 250 }
duke@435 251
duke@435 252
duke@435 253 CodeBlob* Runtime1::blob_for(StubID id) {
duke@435 254 assert(0 <= id && id < number_of_ids, "illegal stub id");
duke@435 255 return _blobs[id];
duke@435 256 }
duke@435 257
duke@435 258
duke@435 259 const char* Runtime1::name_for(StubID id) {
duke@435 260 assert(0 <= id && id < number_of_ids, "illegal stub id");
duke@435 261 return _blob_names[id];
duke@435 262 }
duke@435 263
duke@435 264 const char* Runtime1::name_for_address(address entry) {
duke@435 265 for (int id = 0; id < number_of_ids; id++) {
duke@435 266 if (entry == entry_for((StubID)id)) return name_for((StubID)id);
duke@435 267 }
duke@435 268
duke@435 269 #define FUNCTION_CASE(a, f) \
duke@435 270 if ((intptr_t)a == CAST_FROM_FN_PTR(intptr_t, f)) return #f
duke@435 271
duke@435 272 FUNCTION_CASE(entry, os::javaTimeMillis);
duke@435 273 FUNCTION_CASE(entry, os::javaTimeNanos);
duke@435 274 FUNCTION_CASE(entry, SharedRuntime::OSR_migration_end);
duke@435 275 FUNCTION_CASE(entry, SharedRuntime::d2f);
duke@435 276 FUNCTION_CASE(entry, SharedRuntime::d2i);
duke@435 277 FUNCTION_CASE(entry, SharedRuntime::d2l);
duke@435 278 FUNCTION_CASE(entry, SharedRuntime::dcos);
duke@435 279 FUNCTION_CASE(entry, SharedRuntime::dexp);
duke@435 280 FUNCTION_CASE(entry, SharedRuntime::dlog);
duke@435 281 FUNCTION_CASE(entry, SharedRuntime::dlog10);
duke@435 282 FUNCTION_CASE(entry, SharedRuntime::dpow);
duke@435 283 FUNCTION_CASE(entry, SharedRuntime::drem);
duke@435 284 FUNCTION_CASE(entry, SharedRuntime::dsin);
duke@435 285 FUNCTION_CASE(entry, SharedRuntime::dtan);
duke@435 286 FUNCTION_CASE(entry, SharedRuntime::f2i);
duke@435 287 FUNCTION_CASE(entry, SharedRuntime::f2l);
duke@435 288 FUNCTION_CASE(entry, SharedRuntime::frem);
duke@435 289 FUNCTION_CASE(entry, SharedRuntime::l2d);
duke@435 290 FUNCTION_CASE(entry, SharedRuntime::l2f);
duke@435 291 FUNCTION_CASE(entry, SharedRuntime::ldiv);
duke@435 292 FUNCTION_CASE(entry, SharedRuntime::lmul);
duke@435 293 FUNCTION_CASE(entry, SharedRuntime::lrem);
duke@435 294 FUNCTION_CASE(entry, SharedRuntime::lrem);
duke@435 295 FUNCTION_CASE(entry, SharedRuntime::dtrace_method_entry);
duke@435 296 FUNCTION_CASE(entry, SharedRuntime::dtrace_method_exit);
roland@3838 297 FUNCTION_CASE(entry, is_instance_of);
duke@435 298 FUNCTION_CASE(entry, trace_block_entry);
rbackman@3709 299 #ifdef TRACE_HAVE_INTRINSICS
rbackman@3709 300 FUNCTION_CASE(entry, TRACE_TIME_METHOD);
rbackman@3709 301 #endif
drchase@5353 302 FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32());
duke@435 303
duke@435 304 #undef FUNCTION_CASE
duke@435 305
bobv@2036 306 // Soft float adds more runtime names.
bobv@2036 307 return pd_name_for_address(entry);
duke@435 308 }
duke@435 309
duke@435 310
coleenp@4037 311 JRT_ENTRY(void, Runtime1::new_instance(JavaThread* thread, Klass* klass))
duke@435 312 NOT_PRODUCT(_new_instance_slowcase_cnt++;)
duke@435 313
coleenp@4037 314 assert(klass->is_klass(), "not a class");
vlivanov@8419 315 Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
duke@435 316 instanceKlassHandle h(thread, klass);
duke@435 317 h->check_valid_for_instantiation(true, CHECK);
duke@435 318 // make sure klass is initialized
duke@435 319 h->initialize(CHECK);
duke@435 320 // allocate instance and return via TLS
duke@435 321 oop obj = h->allocate_instance(CHECK);
duke@435 322 thread->set_vm_result(obj);
duke@435 323 JRT_END
duke@435 324
duke@435 325
coleenp@4037 326 JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* thread, Klass* klass, jint length))
duke@435 327 NOT_PRODUCT(_new_type_array_slowcase_cnt++;)
duke@435 328 // Note: no handle for klass needed since they are not used
duke@435 329 // anymore after new_typeArray() and no GC can happen before.
duke@435 330 // (This may have to change if this code changes!)
coleenp@4037 331 assert(klass->is_klass(), "not a class");
coleenp@4142 332 BasicType elt_type = TypeArrayKlass::cast(klass)->element_type();
duke@435 333 oop obj = oopFactory::new_typeArray(elt_type, length, CHECK);
duke@435 334 thread->set_vm_result(obj);
duke@435 335 // This is pretty rare but this runtime patch is stressful to deoptimization
duke@435 336 // if we deoptimize here so force a deopt to stress the path.
duke@435 337 if (DeoptimizeALot) {
duke@435 338 deopt_caller();
duke@435 339 }
duke@435 340
duke@435 341 JRT_END
duke@435 342
duke@435 343
coleenp@4037 344 JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* thread, Klass* array_klass, jint length))
duke@435 345 NOT_PRODUCT(_new_object_array_slowcase_cnt++;)
duke@435 346
duke@435 347 // Note: no handle for klass needed since they are not used
duke@435 348 // anymore after new_objArray() and no GC can happen before.
duke@435 349 // (This may have to change if this code changes!)
coleenp@4037 350 assert(array_klass->is_klass(), "not a class");
vlivanov@8419 351 Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive
coleenp@4142 352 Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
duke@435 353 objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK);
duke@435 354 thread->set_vm_result(obj);
duke@435 355 // This is pretty rare but this runtime patch is stressful to deoptimization
duke@435 356 // if we deoptimize here so force a deopt to stress the path.
duke@435 357 if (DeoptimizeALot) {
duke@435 358 deopt_caller();
duke@435 359 }
duke@435 360 JRT_END
duke@435 361
duke@435 362
coleenp@4037 363 JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims))
duke@435 364 NOT_PRODUCT(_new_multi_array_slowcase_cnt++;)
duke@435 365
coleenp@4037 366 assert(klass->is_klass(), "not a class");
duke@435 367 assert(rank >= 1, "rank must be nonzero");
vlivanov@8419 368 Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
coleenp@4142 369 oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
duke@435 370 thread->set_vm_result(obj);
duke@435 371 JRT_END
duke@435 372
duke@435 373
duke@435 374 JRT_ENTRY(void, Runtime1::unimplemented_entry(JavaThread* thread, StubID id))
duke@435 375 tty->print_cr("Runtime1::entry_for(%d) returned unimplemented entry point", id);
duke@435 376 JRT_END
duke@435 377
duke@435 378
never@2488 379 JRT_ENTRY(void, Runtime1::throw_array_store_exception(JavaThread* thread, oopDesc* obj))
never@2488 380 ResourceMark rm(thread);
hseigel@4278 381 const char* klass_name = obj->klass()->external_name();
never@2488 382 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArrayStoreException(), klass_name);
duke@435 383 JRT_END
duke@435 384
duke@435 385
iveresov@2988 386 // counter_overflow() is called from within C1-compiled methods. The enclosing method is the method
iveresov@2988 387 // associated with the top activation record. The inlinee (that is possibly included in the enclosing
iveresov@2988 388 // method) method oop is passed as an argument. In order to do that it is embedded in the code as
iveresov@2988 389 // a constant.
coleenp@4037 390 static nmethod* counter_overflow_helper(JavaThread* THREAD, int branch_bci, Method* m) {
iveresov@2138 391 nmethod* osr_nm = NULL;
iveresov@2138 392 methodHandle method(THREAD, m);
iveresov@2138 393
iveresov@2138 394 RegisterMap map(THREAD, false);
iveresov@2138 395 frame fr = THREAD->last_frame().sender(&map);
duke@435 396 nmethod* nm = (nmethod*) fr.cb();
iveresov@2138 397 assert(nm!= NULL && nm->is_nmethod(), "Sanity check");
iveresov@2138 398 methodHandle enclosing_method(THREAD, nm->method());
iveresov@2138 399
iveresov@2138 400 CompLevel level = (CompLevel)nm->comp_level();
iveresov@2138 401 int bci = InvocationEntryBci;
iveresov@2138 402 if (branch_bci != InvocationEntryBci) {
iveresov@2138 403 // Compute desination bci
iveresov@2138 404 address pc = method()->code_base() + branch_bci;
never@2462 405 Bytecodes::Code branch = Bytecodes::code_at(method(), pc);
iveresov@2138 406 int offset = 0;
iveresov@2138 407 switch (branch) {
iveresov@2138 408 case Bytecodes::_if_icmplt: case Bytecodes::_iflt:
iveresov@2138 409 case Bytecodes::_if_icmpgt: case Bytecodes::_ifgt:
iveresov@2138 410 case Bytecodes::_if_icmple: case Bytecodes::_ifle:
iveresov@2138 411 case Bytecodes::_if_icmpge: case Bytecodes::_ifge:
iveresov@2138 412 case Bytecodes::_if_icmpeq: case Bytecodes::_if_acmpeq: case Bytecodes::_ifeq:
iveresov@2138 413 case Bytecodes::_if_icmpne: case Bytecodes::_if_acmpne: case Bytecodes::_ifne:
iveresov@2138 414 case Bytecodes::_ifnull: case Bytecodes::_ifnonnull: case Bytecodes::_goto:
iveresov@2138 415 offset = (int16_t)Bytes::get_Java_u2(pc + 1);
iveresov@2138 416 break;
iveresov@2138 417 case Bytecodes::_goto_w:
iveresov@2138 418 offset = Bytes::get_Java_u4(pc + 1);
iveresov@2138 419 break;
iveresov@2138 420 default: ;
duke@435 421 }
iveresov@2138 422 bci = branch_bci + offset;
iveresov@2138 423 }
iveresov@3452 424 assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending");
iveresov@2988 425 osr_nm = CompilationPolicy::policy()->event(enclosing_method, method, branch_bci, bci, level, nm, THREAD);
iveresov@3452 426 assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions");
iveresov@2138 427 return osr_nm;
iveresov@2138 428 }
iveresov@2138 429
coleenp@4037 430 JRT_BLOCK_ENTRY(address, Runtime1::counter_overflow(JavaThread* thread, int bci, Method* method))
iveresov@2138 431 nmethod* osr_nm;
iveresov@2138 432 JRT_BLOCK
iveresov@2138 433 osr_nm = counter_overflow_helper(thread, bci, method);
iveresov@2138 434 if (osr_nm != NULL) {
iveresov@2138 435 RegisterMap map(thread, false);
iveresov@2138 436 frame fr = thread->last_frame().sender(&map);
never@2260 437 Deoptimization::deoptimize_frame(thread, fr.id());
duke@435 438 }
iveresov@2138 439 JRT_BLOCK_END
iveresov@2138 440 return NULL;
duke@435 441 JRT_END
duke@435 442
duke@435 443 extern void vm_exit(int code);
duke@435 444
duke@435 445 // Enter this method from compiled code handler below. This is where we transition
duke@435 446 // to VM mode. This is done as a helper routine so that the method called directly
duke@435 447 // from compiled code does not have to transition to VM. This allows the entry
duke@435 448 // method to see if the nmethod that we have just looked up a handler for has
duke@435 449 // been deoptimized while we were in the vm. This simplifies the assembly code
duke@435 450 // cpu directories.
duke@435 451 //
duke@435 452 // We are entering here from exception stub (via the entry method below)
duke@435 453 // If there is a compiled exception handler in this method, we will continue there;
duke@435 454 // otherwise we will unwind the stack and continue at the caller of top frame method
duke@435 455 // Note: we enter in Java using a special JRT wrapper. This wrapper allows us to
duke@435 456 // control the area where we can allow a safepoint. After we exit the safepoint area we can
duke@435 457 // check to see if the handler we are going to return is now in a nmethod that has
duke@435 458 // been deoptimized. If that is the case we return the deopt blob
duke@435 459 // unpack_with_exception entry instead. This makes life for the exception blob easier
duke@435 460 // because making that same check and diverting is painful from assembly language.
duke@435 461 JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* thread, oopDesc* ex, address pc, nmethod*& nm))
twisti@2603 462 // Reset method handle flag.
twisti@2603 463 thread->set_is_method_handle_return(false);
duke@435 464
duke@435 465 Handle exception(thread, ex);
duke@435 466 nm = CodeCache::find_nmethod(pc);
duke@435 467 assert(nm != NULL, "this is not an nmethod");
duke@435 468 // Adjust the pc as needed/
duke@435 469 if (nm->is_deopt_pc(pc)) {
duke@435 470 RegisterMap map(thread, false);
duke@435 471 frame exception_frame = thread->last_frame().sender(&map);
duke@435 472 // if the frame isn't deopted then pc must not correspond to the caller of last_frame
duke@435 473 assert(exception_frame.is_deoptimized_frame(), "must be deopted");
duke@435 474 pc = exception_frame.pc();
duke@435 475 }
duke@435 476 #ifdef ASSERT
duke@435 477 assert(exception.not_null(), "NULL exceptions should be handled by throw_exception");
duke@435 478 assert(exception->is_oop(), "just checking");
duke@435 479 // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
never@1577 480 if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
duke@435 481 if (ExitVMOnVerifyError) vm_exit(-1);
duke@435 482 ShouldNotReachHere();
duke@435 483 }
duke@435 484 #endif
duke@435 485
duke@435 486 // Check the stack guard pages and reenable them if necessary and there is
duke@435 487 // enough space on the stack to do so. Use fast exceptions only if the guard
duke@435 488 // pages are enabled.
duke@435 489 bool guard_pages_enabled = thread->stack_yellow_zone_enabled();
duke@435 490 if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack();
duke@435 491
dcubed@1648 492 if (JvmtiExport::can_post_on_exceptions()) {
duke@435 493 // To ensure correct notification of exception catches and throws
duke@435 494 // we have to deoptimize here. If we attempted to notify the
duke@435 495 // catches and throws during this exception lookup it's possible
duke@435 496 // we could deoptimize on the way out of the VM and end back in
duke@435 497 // the interpreter at the throw site. This would result in double
duke@435 498 // notifications since the interpreter would also notify about
duke@435 499 // these same catches and throws as it unwound the frame.
duke@435 500
duke@435 501 RegisterMap reg_map(thread);
duke@435 502 frame stub_frame = thread->last_frame();
duke@435 503 frame caller_frame = stub_frame.sender(&reg_map);
duke@435 504
duke@435 505 // We don't really want to deoptimize the nmethod itself since we
duke@435 506 // can actually continue in the exception handler ourselves but I
duke@435 507 // don't see an easy way to have the desired effect.
never@2260 508 Deoptimization::deoptimize_frame(thread, caller_frame.id());
never@2260 509 assert(caller_is_deopted(), "Must be deoptimized");
duke@435 510
duke@435 511 return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
duke@435 512 }
duke@435 513
twisti@2603 514 // ExceptionCache is used only for exceptions at call sites and not for implicit exceptions
duke@435 515 if (guard_pages_enabled) {
duke@435 516 address fast_continuation = nm->handler_for_exception_and_pc(exception, pc);
duke@435 517 if (fast_continuation != NULL) {
twisti@2603 518 // Set flag if return address is a method handle call site.
twisti@2603 519 thread->set_is_method_handle_return(nm->is_method_handle_return(pc));
duke@435 520 return fast_continuation;
duke@435 521 }
duke@435 522 }
duke@435 523
duke@435 524 // If the stack guard pages are enabled, check whether there is a handler in
duke@435 525 // the current method. Otherwise (guard pages disabled), force an unwind and
duke@435 526 // skip the exception cache update (i.e., just leave continuation==NULL).
duke@435 527 address continuation = NULL;
duke@435 528 if (guard_pages_enabled) {
duke@435 529
duke@435 530 // New exception handling mechanism can support inlined methods
duke@435 531 // with exception handlers since the mappings are from PC to PC
duke@435 532
duke@435 533 // debugging support
duke@435 534 // tracing
duke@435 535 if (TraceExceptions) {
duke@435 536 ttyLocker ttyl;
duke@435 537 ResourceMark rm;
drchase@6680 538 tty->print_cr("Exception <%s> (" INTPTR_FORMAT ") thrown in compiled method <%s> at PC " INTPTR_FORMAT " for thread " INTPTR_FORMAT "",
drchase@6680 539 exception->print_value_string(), p2i((address)exception()), nm->method()->print_value_string(), p2i(pc), p2i(thread));
duke@435 540 }
duke@435 541 // for AbortVMOnException flag
duke@435 542 NOT_PRODUCT(Exceptions::debug_check_abort(exception));
duke@435 543
duke@435 544 // Clear out the exception oop and pc since looking up an
duke@435 545 // exception handler can cause class loading, which might throw an
duke@435 546 // exception and those fields are expected to be clear during
duke@435 547 // normal bytecode execution.
twisti@5915 548 thread->clear_exception_oop_and_pc();
duke@435 549
roland@7167 550 Handle original_exception(thread, exception());
roland@7167 551
duke@435 552 continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false);
duke@435 553 // If an exception was thrown during exception dispatch, the exception oop may have changed
duke@435 554 thread->set_exception_oop(exception());
duke@435 555 thread->set_exception_pc(pc);
duke@435 556
duke@435 557 // the exception cache is used only by non-implicit exceptions
roland@7167 558 // Update the exception cache only when there didn't happen
roland@7167 559 // another exception during the computation of the compiled
roland@7167 560 // exception handler.
roland@7167 561 if (continuation != NULL && original_exception() == exception()) {
duke@435 562 nm->add_handler_for_exception_and_pc(exception, pc, continuation);
duke@435 563 }
duke@435 564 }
duke@435 565
duke@435 566 thread->set_vm_result(exception());
twisti@2603 567 // Set flag if return address is a method handle call site.
twisti@2603 568 thread->set_is_method_handle_return(nm->is_method_handle_return(pc));
duke@435 569
duke@435 570 if (TraceExceptions) {
duke@435 571 ttyLocker ttyl;
duke@435 572 ResourceMark rm;
duke@435 573 tty->print_cr("Thread " PTR_FORMAT " continuing at PC " PTR_FORMAT " for exception thrown at PC " PTR_FORMAT,
drchase@6680 574 p2i(thread), p2i(continuation), p2i(pc));
duke@435 575 }
duke@435 576
duke@435 577 return continuation;
duke@435 578 JRT_END
duke@435 579
duke@435 580 // Enter this method from compiled code only if there is a Java exception handler
twisti@2603 581 // in the method handling the exception.
duke@435 582 // We are entering here from exception stub. We don't do a normal VM transition here.
duke@435 583 // We do it in a helper. This is so we can check to see if the nmethod we have just
duke@435 584 // searched for an exception handler has been deoptimized in the meantime.
twisti@2603 585 address Runtime1::exception_handler_for_pc(JavaThread* thread) {
duke@435 586 oop exception = thread->exception_oop();
duke@435 587 address pc = thread->exception_pc();
duke@435 588 // Still in Java mode
twisti@2603 589 DEBUG_ONLY(ResetNoHandleMark rnhm);
duke@435 590 nmethod* nm = NULL;
duke@435 591 address continuation = NULL;
duke@435 592 {
duke@435 593 // Enter VM mode by calling the helper
duke@435 594 ResetNoHandleMark rnhm;
duke@435 595 continuation = exception_handler_for_pc_helper(thread, exception, pc, nm);
duke@435 596 }
duke@435 597 // Back in JAVA, use no oops DON'T safepoint
duke@435 598
duke@435 599 // Now check to see if the nmethod we were called from is now deoptimized.
duke@435 600 // If so we must return to the deopt blob and deoptimize the nmethod
duke@435 601 if (nm != NULL && caller_is_deopted()) {
duke@435 602 continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
duke@435 603 }
duke@435 604
twisti@2603 605 assert(continuation != NULL, "no handler found");
duke@435 606 return continuation;
duke@435 607 }
duke@435 608
duke@435 609
duke@435 610 JRT_ENTRY(void, Runtime1::throw_range_check_exception(JavaThread* thread, int index))
duke@435 611 NOT_PRODUCT(_throw_range_check_exception_count++;)
duke@435 612 char message[jintAsStringSize];
duke@435 613 sprintf(message, "%d", index);
duke@435 614 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), message);
duke@435 615 JRT_END
duke@435 616
duke@435 617
duke@435 618 JRT_ENTRY(void, Runtime1::throw_index_exception(JavaThread* thread, int index))
duke@435 619 NOT_PRODUCT(_throw_index_exception_count++;)
duke@435 620 char message[16];
duke@435 621 sprintf(message, "%d", index);
duke@435 622 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IndexOutOfBoundsException(), message);
duke@435 623 JRT_END
duke@435 624
duke@435 625
duke@435 626 JRT_ENTRY(void, Runtime1::throw_div0_exception(JavaThread* thread))
duke@435 627 NOT_PRODUCT(_throw_div0_exception_count++;)
duke@435 628 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArithmeticException(), "/ by zero");
duke@435 629 JRT_END
duke@435 630
duke@435 631
duke@435 632 JRT_ENTRY(void, Runtime1::throw_null_pointer_exception(JavaThread* thread))
duke@435 633 NOT_PRODUCT(_throw_null_pointer_exception_count++;)
duke@435 634 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException());
duke@435 635 JRT_END
duke@435 636
duke@435 637
duke@435 638 JRT_ENTRY(void, Runtime1::throw_class_cast_exception(JavaThread* thread, oopDesc* object))
duke@435 639 NOT_PRODUCT(_throw_class_cast_exception_count++;)
duke@435 640 ResourceMark rm(thread);
duke@435 641 char* message = SharedRuntime::generate_class_cast_message(
hseigel@4278 642 thread, object->klass()->external_name());
duke@435 643 SharedRuntime::throw_and_post_jvmti_exception(
duke@435 644 thread, vmSymbols::java_lang_ClassCastException(), message);
duke@435 645 JRT_END
duke@435 646
duke@435 647
duke@435 648 JRT_ENTRY(void, Runtime1::throw_incompatible_class_change_error(JavaThread* thread))
duke@435 649 NOT_PRODUCT(_throw_incompatible_class_change_error_count++;)
duke@435 650 ResourceMark rm(thread);
duke@435 651 SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IncompatibleClassChangeError());
duke@435 652 JRT_END
duke@435 653
duke@435 654
duke@435 655 JRT_ENTRY_NO_ASYNC(void, Runtime1::monitorenter(JavaThread* thread, oopDesc* obj, BasicObjectLock* lock))
duke@435 656 NOT_PRODUCT(_monitorenter_slowcase_cnt++;)
duke@435 657 if (PrintBiasedLockingStatistics) {
duke@435 658 Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
duke@435 659 }
duke@435 660 Handle h_obj(thread, obj);
duke@435 661 assert(h_obj()->is_oop(), "must be NULL or an object");
duke@435 662 if (UseBiasedLocking) {
duke@435 663 // Retry fast entry if bias is revoked to avoid unnecessary inflation
duke@435 664 ObjectSynchronizer::fast_enter(h_obj, lock->lock(), true, CHECK);
duke@435 665 } else {
duke@435 666 if (UseFastLocking) {
duke@435 667 // When using fast locking, the compiled code has already tried the fast case
duke@435 668 assert(obj == lock->obj(), "must match");
duke@435 669 ObjectSynchronizer::slow_enter(h_obj, lock->lock(), THREAD);
duke@435 670 } else {
duke@435 671 lock->set_obj(obj);
duke@435 672 ObjectSynchronizer::fast_enter(h_obj, lock->lock(), false, THREAD);
duke@435 673 }
duke@435 674 }
duke@435 675 JRT_END
duke@435 676
duke@435 677
duke@435 678 JRT_LEAF(void, Runtime1::monitorexit(JavaThread* thread, BasicObjectLock* lock))
duke@435 679 NOT_PRODUCT(_monitorexit_slowcase_cnt++;)
duke@435 680 assert(thread == JavaThread::current(), "threads must correspond");
duke@435 681 assert(thread->last_Java_sp(), "last_Java_sp must be set");
duke@435 682 // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown
duke@435 683 EXCEPTION_MARK;
duke@435 684
duke@435 685 oop obj = lock->obj();
duke@435 686 assert(obj->is_oop(), "must be NULL or an object");
duke@435 687 if (UseFastLocking) {
duke@435 688 // When using fast locking, the compiled code has already tried the fast case
duke@435 689 ObjectSynchronizer::slow_exit(obj, lock->lock(), THREAD);
duke@435 690 } else {
duke@435 691 ObjectSynchronizer::fast_exit(obj, lock->lock(), THREAD);
duke@435 692 }
duke@435 693 JRT_END
duke@435 694
twisti@3244 695 // Cf. OptoRuntime::deoptimize_caller_frame
twisti@3244 696 JRT_ENTRY(void, Runtime1::deoptimize(JavaThread* thread))
twisti@3244 697 // Called from within the owner thread, so no need for safepoint
twisti@3244 698 RegisterMap reg_map(thread, false);
twisti@3244 699 frame stub_frame = thread->last_frame();
twisti@3244 700 assert(stub_frame.is_runtime_frame(), "sanity check");
twisti@3244 701 frame caller_frame = stub_frame.sender(&reg_map);
twisti@3244 702
twisti@3244 703 // We are coming from a compiled method; check this is true.
twisti@3244 704 assert(CodeCache::find_nmethod(caller_frame.pc()) != NULL, "sanity");
twisti@3244 705
twisti@3244 706 // Deoptimize the caller frame.
twisti@3244 707 Deoptimization::deoptimize_frame(thread, caller_frame.id());
twisti@3244 708
twisti@3244 709 // Return to the now deoptimized frame.
twisti@3244 710 JRT_END
twisti@3244 711
duke@435 712
coleenp@4037 713 static Klass* resolve_field_return_klass(methodHandle caller, int bci, TRAPS) {
never@2462 714 Bytecode_field field_access(caller, bci);
duke@435 715 // This can be static or non-static field access
never@2462 716 Bytecodes::Code code = field_access.code();
duke@435 717
duke@435 718 // We must load class, initialize class and resolvethe field
drchase@5732 719 fieldDescriptor result; // initialize class if needed
duke@435 720 constantPoolHandle constants(THREAD, caller->constants());
drchase@5732 721 LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK_NULL);
drchase@5732 722 return result.field_holder();
duke@435 723 }
duke@435 724
duke@435 725
duke@435 726 //
duke@435 727 // This routine patches sites where a class wasn't loaded or
duke@435 728 // initialized at the time the code was generated. It handles
duke@435 729 // references to classes, fields and forcing of initialization. Most
duke@435 730 // of the cases are straightforward and involving simply forcing
duke@435 731 // resolution of a class, rewriting the instruction stream with the
duke@435 732 // needed constant and replacing the call in this function with the
duke@435 733 // patched code. The case for static field is more complicated since
duke@435 734 // the thread which is in the process of initializing a class can
duke@435 735 // access it's static fields but other threads can't so the code
duke@435 736 // either has to deoptimize when this case is detected or execute a
duke@435 737 // check that the current thread is the initializing thread. The
duke@435 738 // current
duke@435 739 //
duke@435 740 // Patches basically look like this:
duke@435 741 //
duke@435 742 //
duke@435 743 // patch_site: jmp patch stub ;; will be patched
duke@435 744 // continue: ...
duke@435 745 // ...
duke@435 746 // ...
duke@435 747 // ...
duke@435 748 //
duke@435 749 // They have a stub which looks like this:
duke@435 750 //
duke@435 751 // ;; patch body
duke@435 752 // movl <const>, reg (for class constants)
duke@435 753 // <or> movl [reg1 + <const>], reg (for field offsets)
duke@435 754 // <or> movl reg, [reg1 + <const>] (for field offsets)
duke@435 755 // <being_init offset> <bytes to copy> <bytes to skip>
duke@435 756 // patch_stub: call Runtime1::patch_code (through a runtime stub)
duke@435 757 // jmp patch_site
duke@435 758 //
duke@435 759 //
duke@435 760 // A normal patch is done by rewriting the patch body, usually a move,
duke@435 761 // and then copying it into place over top of the jmp instruction
duke@435 762 // being careful to flush caches and doing it in an MP-safe way. The
duke@435 763 // constants following the patch body are used to find various pieces
duke@435 764 // of the patch relative to the call site for Runtime1::patch_code.
duke@435 765 // The case for getstatic and putstatic is more complicated because
duke@435 766 // getstatic and putstatic have special semantics when executing while
duke@435 767 // the class is being initialized. getstatic/putstatic on a class
duke@435 768 // which is being_initialized may be executed by the initializing
duke@435 769 // thread but other threads have to block when they execute it. This
duke@435 770 // is accomplished in compiled code by executing a test of the current
duke@435 771 // thread against the initializing thread of the class. It's emitted
duke@435 772 // as boilerplate in their stub which allows the patched code to be
duke@435 773 // executed before it's copied back into the main body of the nmethod.
duke@435 774 //
duke@435 775 // being_init: get_thread(<tmp reg>
duke@435 776 // cmpl [reg1 + <init_thread_offset>], <tmp reg>
duke@435 777 // jne patch_stub
duke@435 778 // movl [reg1 + <const>], reg (for field offsets) <or>
duke@435 779 // movl reg, [reg1 + <const>] (for field offsets)
duke@435 780 // jmp continue
duke@435 781 // <being_init offset> <bytes to copy> <bytes to skip>
duke@435 782 // patch_stub: jmp Runtim1::patch_code (through a runtime stub)
duke@435 783 // jmp patch_site
duke@435 784 //
duke@435 785 // If the class is being initialized the patch body is rewritten and
duke@435 786 // the patch site is rewritten to jump to being_init, instead of
duke@435 787 // patch_stub. Whenever this code is executed it checks the current
duke@435 788 // thread against the intializing thread so other threads will enter
duke@435 789 // the runtime and end up blocked waiting the class to finish
duke@435 790 // initializing inside the calls to resolve_field below. The
duke@435 791 // initializing class will continue on it's way. Once the class is
duke@435 792 // fully_initialized, the intializing_thread of the class becomes
duke@435 793 // NULL, so the next thread to execute this code will fail the test,
duke@435 794 // call into patch_code and complete the patching process by copying
duke@435 795 // the patch body back into the main part of the nmethod and resume
duke@435 796 // executing.
duke@435 797 //
duke@435 798 //
duke@435 799
duke@435 800 JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id ))
duke@435 801 NOT_PRODUCT(_patch_code_slowcase_cnt++;)
duke@435 802
duke@435 803 ResourceMark rm(thread);
duke@435 804 RegisterMap reg_map(thread, false);
duke@435 805 frame runtime_frame = thread->last_frame();
duke@435 806 frame caller_frame = runtime_frame.sender(&reg_map);
duke@435 807
duke@435 808 // last java frame on stack
duke@435 809 vframeStream vfst(thread, true);
duke@435 810 assert(!vfst.at_end(), "Java frame must exist");
duke@435 811
duke@435 812 methodHandle caller_method(THREAD, vfst.method());
duke@435 813 // Note that caller_method->code() may not be same as caller_code because of OSR's
duke@435 814 // Note also that in the presence of inlining it is not guaranteed
duke@435 815 // that caller_method() == caller_code->method()
duke@435 816
duke@435 817 int bci = vfst.bci();
never@2462 818 Bytecodes::Code code = caller_method()->java_code_at(bci);
duke@435 819
duke@435 820 #ifndef PRODUCT
duke@435 821 // this is used by assertions in the access_field_patching_id
duke@435 822 BasicType patch_field_type = T_ILLEGAL;
duke@435 823 #endif // PRODUCT
duke@435 824 bool deoptimize_for_volatile = false;
duke@435 825 int patch_field_offset = -1;
coleenp@4037 826 KlassHandle init_klass(THREAD, NULL); // klass needed by load_klass_patching code
coleenp@4037 827 KlassHandle load_klass(THREAD, NULL); // klass needed by load_klass_patching code
coleenp@4037 828 Handle mirror(THREAD, NULL); // oop needed by load_mirror_patching code
roland@5628 829 Handle appendix(THREAD, NULL); // oop needed by appendix_patching code
coleenp@4037 830 bool load_klass_or_mirror_patch_id =
coleenp@4037 831 (stub_id == Runtime1::load_klass_patching_id || stub_id == Runtime1::load_mirror_patching_id);
coleenp@4037 832
duke@435 833 if (stub_id == Runtime1::access_field_patching_id) {
duke@435 834
never@2462 835 Bytecode_field field_access(caller_method, bci);
drchase@5732 836 fieldDescriptor result; // initialize class if needed
never@2462 837 Bytecodes::Code code = field_access.code();
duke@435 838 constantPoolHandle constants(THREAD, caller_method->constants());
drchase@5732 839 LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK);
drchase@5732 840 patch_field_offset = result.offset();
duke@435 841
duke@435 842 // If we're patching a field which is volatile then at compile it
duke@435 843 // must not have been know to be volatile, so the generated code
duke@435 844 // isn't correct for a volatile reference. The nmethod has to be
duke@435 845 // deoptimized so that the code can be regenerated correctly.
duke@435 846 // This check is only needed for access_field_patching since this
duke@435 847 // is the path for patching field offsets. load_klass is only
duke@435 848 // used for patching references to oops which don't need special
duke@435 849 // handling in the volatile case.
duke@435 850 deoptimize_for_volatile = result.access_flags().is_volatile();
duke@435 851
duke@435 852 #ifndef PRODUCT
duke@435 853 patch_field_type = result.field_type();
duke@435 854 #endif
coleenp@4037 855 } else if (load_klass_or_mirror_patch_id) {
coleenp@4037 856 Klass* k = NULL;
duke@435 857 switch (code) {
duke@435 858 case Bytecodes::_putstatic:
duke@435 859 case Bytecodes::_getstatic:
coleenp@4037 860 { Klass* klass = resolve_field_return_klass(caller_method, bci, CHECK);
duke@435 861 init_klass = KlassHandle(THREAD, klass);
coleenp@4037 862 mirror = Handle(THREAD, klass->java_mirror());
duke@435 863 }
duke@435 864 break;
duke@435 865 case Bytecodes::_new:
never@2462 866 { Bytecode_new bnew(caller_method(), caller_method->bcp_from(bci));
never@2462 867 k = caller_method->constants()->klass_at(bnew.index(), CHECK);
duke@435 868 }
duke@435 869 break;
duke@435 870 case Bytecodes::_multianewarray:
never@2462 871 { Bytecode_multianewarray mna(caller_method(), caller_method->bcp_from(bci));
never@2462 872 k = caller_method->constants()->klass_at(mna.index(), CHECK);
duke@435 873 }
duke@435 874 break;
duke@435 875 case Bytecodes::_instanceof:
never@2462 876 { Bytecode_instanceof io(caller_method(), caller_method->bcp_from(bci));
never@2462 877 k = caller_method->constants()->klass_at(io.index(), CHECK);
duke@435 878 }
duke@435 879 break;
duke@435 880 case Bytecodes::_checkcast:
never@2462 881 { Bytecode_checkcast cc(caller_method(), caller_method->bcp_from(bci));
never@2462 882 k = caller_method->constants()->klass_at(cc.index(), CHECK);
duke@435 883 }
duke@435 884 break;
duke@435 885 case Bytecodes::_anewarray:
never@2462 886 { Bytecode_anewarray anew(caller_method(), caller_method->bcp_from(bci));
coleenp@4037 887 Klass* ek = caller_method->constants()->klass_at(anew.index(), CHECK);
hseigel@4278 888 k = ek->array_klass(CHECK);
duke@435 889 }
duke@435 890 break;
duke@435 891 case Bytecodes::_ldc:
duke@435 892 case Bytecodes::_ldc_w:
duke@435 893 {
never@2462 894 Bytecode_loadconstant cc(caller_method, bci);
coleenp@4037 895 oop m = cc.resolve_constant(CHECK);
coleenp@4037 896 mirror = Handle(THREAD, m);
duke@435 897 }
duke@435 898 break;
roland@5628 899 default: fatal("unexpected bytecode for load_klass_or_mirror_patch_id");
duke@435 900 }
duke@435 901 // convert to handle
coleenp@4037 902 load_klass = KlassHandle(THREAD, k);
roland@5628 903 } else if (stub_id == load_appendix_patching_id) {
roland@5628 904 Bytecode_invoke bytecode(caller_method, bci);
roland@5628 905 Bytecodes::Code bc = bytecode.invoke_code();
roland@5628 906
roland@5628 907 CallInfo info;
roland@5628 908 constantPoolHandle pool(thread, caller_method->constants());
roland@5628 909 int index = bytecode.index();
roland@5628 910 LinkResolver::resolve_invoke(info, Handle(), pool, index, bc, CHECK);
roland@5628 911 appendix = info.resolved_appendix();
roland@5628 912 switch (bc) {
roland@5628 913 case Bytecodes::_invokehandle: {
roland@5628 914 int cache_index = ConstantPool::decode_cpcache_index(index, true);
roland@5628 915 assert(cache_index >= 0 && cache_index < pool->cache()->length(), "unexpected cache index");
roland@5628 916 pool->cache()->entry_at(cache_index)->set_method_handle(pool, info);
roland@5628 917 break;
roland@5628 918 }
roland@5628 919 case Bytecodes::_invokedynamic: {
roland@5628 920 pool->invokedynamic_cp_cache_entry_at(index)->set_dynamic_call(pool, info);
roland@5628 921 break;
roland@5628 922 }
roland@5628 923 default: fatal("unexpected bytecode for load_appendix_patching_id");
roland@5628 924 }
duke@435 925 } else {
duke@435 926 ShouldNotReachHere();
duke@435 927 }
duke@435 928
duke@435 929 if (deoptimize_for_volatile) {
duke@435 930 // At compile time we assumed the field wasn't volatile but after
duke@435 931 // loading it turns out it was volatile so we have to throw the
duke@435 932 // compiled code out and let it be regenerated.
duke@435 933 if (TracePatching) {
duke@435 934 tty->print_cr("Deoptimizing for patching volatile field reference");
duke@435 935 }
never@920 936 // It's possible the nmethod was invalidated in the last
never@920 937 // safepoint, but if it's still alive then make it not_entrant.
never@920 938 nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
never@920 939 if (nm != NULL) {
never@920 940 nm->make_not_entrant();
never@920 941 }
never@920 942
never@2260 943 Deoptimization::deoptimize_frame(thread, caller_frame.id());
duke@435 944
duke@435 945 // Return to the now deoptimized frame.
duke@435 946 }
duke@435 947
duke@435 948 // Now copy code back
duke@435 949
duke@435 950 {
duke@435 951 MutexLockerEx ml_patch (Patching_lock, Mutex::_no_safepoint_check_flag);
duke@435 952 //
duke@435 953 // Deoptimization may have happened while we waited for the lock.
duke@435 954 // In that case we don't bother to do any patching we just return
duke@435 955 // and let the deopt happen
duke@435 956 if (!caller_is_deopted()) {
duke@435 957 NativeGeneralJump* jump = nativeGeneralJump_at(caller_frame.pc());
duke@435 958 address instr_pc = jump->jump_destination();
duke@435 959 NativeInstruction* ni = nativeInstruction_at(instr_pc);
duke@435 960 if (ni->is_jump() ) {
duke@435 961 // the jump has not been patched yet
duke@435 962 // The jump destination is slow case and therefore not part of the stubs
duke@435 963 // (stubs are only for StaticCalls)
duke@435 964
duke@435 965 // format of buffer
duke@435 966 // ....
duke@435 967 // instr byte 0 <-- copy_buff
duke@435 968 // instr byte 1
duke@435 969 // ..
duke@435 970 // instr byte n-1
duke@435 971 // n
duke@435 972 // .... <-- call destination
duke@435 973
duke@435 974 address stub_location = caller_frame.pc() + PatchingStub::patch_info_offset();
duke@435 975 unsigned char* byte_count = (unsigned char*) (stub_location - 1);
duke@435 976 unsigned char* byte_skip = (unsigned char*) (stub_location - 2);
duke@435 977 unsigned char* being_initialized_entry_offset = (unsigned char*) (stub_location - 3);
duke@435 978 address copy_buff = stub_location - *byte_skip - *byte_count;
duke@435 979 address being_initialized_entry = stub_location - *being_initialized_entry_offset;
duke@435 980 if (TracePatching) {
drchase@6680 981 tty->print_cr(" Patching %s at bci %d at address " INTPTR_FORMAT " (%s)", Bytecodes::name(code), bci,
drchase@6680 982 p2i(instr_pc), (stub_id == Runtime1::access_field_patching_id) ? "field" : "klass");
duke@435 983 nmethod* caller_code = CodeCache::find_nmethod(caller_frame.pc());
duke@435 984 assert(caller_code != NULL, "nmethod not found");
duke@435 985
duke@435 986 // NOTE we use pc() not original_pc() because we already know they are
duke@435 987 // identical otherwise we'd have never entered this block of code
duke@435 988
duke@435 989 OopMap* map = caller_code->oop_map_for_return_address(caller_frame.pc());
duke@435 990 assert(map != NULL, "null check");
duke@435 991 map->print();
duke@435 992 tty->cr();
duke@435 993
duke@435 994 Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);
duke@435 995 }
duke@435 996 // depending on the code below, do_patch says whether to copy the patch body back into the nmethod
duke@435 997 bool do_patch = true;
duke@435 998 if (stub_id == Runtime1::access_field_patching_id) {
duke@435 999 // The offset may not be correct if the class was not loaded at code generation time.
duke@435 1000 // Set it now.
duke@435 1001 NativeMovRegMem* n_move = nativeMovRegMem_at(copy_buff);
duke@435 1002 assert(n_move->offset() == 0 || (n_move->offset() == 4 && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG)), "illegal offset for type");
duke@435 1003 assert(patch_field_offset >= 0, "illegal offset");
duke@435 1004 n_move->add_offset_in_bytes(patch_field_offset);
coleenp@4037 1005 } else if (load_klass_or_mirror_patch_id) {
duke@435 1006 // If a getstatic or putstatic is referencing a klass which
duke@435 1007 // isn't fully initialized, the patch body isn't copied into
duke@435 1008 // place until initialization is complete. In this case the
duke@435 1009 // patch site is setup so that any threads besides the
duke@435 1010 // initializing thread are forced to come into the VM and
duke@435 1011 // block.
duke@435 1012 do_patch = (code != Bytecodes::_getstatic && code != Bytecodes::_putstatic) ||
coleenp@4037 1013 InstanceKlass::cast(init_klass())->is_initialized();
duke@435 1014 NativeGeneralJump* jump = nativeGeneralJump_at(instr_pc);
duke@435 1015 if (jump->jump_destination() == being_initialized_entry) {
duke@435 1016 assert(do_patch == true, "initialization must be complete at this point");
duke@435 1017 } else {
duke@435 1018 // patch the instruction <move reg, klass>
duke@435 1019 NativeMovConstReg* n_copy = nativeMovConstReg_at(copy_buff);
bobv@2036 1020
bobv@2036 1021 assert(n_copy->data() == 0 ||
iveresov@2138 1022 n_copy->data() == (intptr_t)Universe::non_oop_word(),
bobv@2036 1023 "illegal init value");
coleenp@4037 1024 if (stub_id == Runtime1::load_klass_patching_id) {
roland@5628 1025 assert(load_klass() != NULL, "klass not set");
roland@5628 1026 n_copy->set_data((intx) (load_klass()));
coleenp@4037 1027 } else {
coleenp@4037 1028 assert(mirror() != NULL, "klass not set");
stefank@6992 1029 // Don't need a G1 pre-barrier here since we assert above that data isn't an oop.
hseigel@5784 1030 n_copy->set_data(cast_from_oop<intx>(mirror()));
coleenp@4037 1031 }
duke@435 1032
duke@435 1033 if (TracePatching) {
duke@435 1034 Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);
duke@435 1035 }
roland@5628 1036 }
roland@5628 1037 } else if (stub_id == Runtime1::load_appendix_patching_id) {
roland@5628 1038 NativeMovConstReg* n_copy = nativeMovConstReg_at(copy_buff);
roland@5628 1039 assert(n_copy->data() == 0 ||
roland@5628 1040 n_copy->data() == (intptr_t)Universe::non_oop_word(),
roland@5628 1041 "illegal init value");
hseigel@5784 1042 n_copy->set_data(cast_from_oop<intx>(appendix()));
duke@435 1043
roland@5628 1044 if (TracePatching) {
roland@5628 1045 Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);
duke@435 1046 }
duke@435 1047 } else {
duke@435 1048 ShouldNotReachHere();
duke@435 1049 }
coleenp@4037 1050
roland@5628 1051 #if defined(SPARC) || defined(PPC)
roland@5628 1052 if (load_klass_or_mirror_patch_id ||
roland@5628 1053 stub_id == Runtime1::load_appendix_patching_id) {
roland@5628 1054 // Update the location in the nmethod with the proper
roland@5628 1055 // metadata. When the code was generated, a NULL was stuffed
roland@5628 1056 // in the metadata table and that table needs to be update to
roland@5628 1057 // have the right value. On intel the value is kept
roland@5628 1058 // directly in the instruction instead of in the metadata
roland@5628 1059 // table, so set_data above effectively updated the value.
roland@5628 1060 nmethod* nm = CodeCache::find_nmethod(instr_pc);
roland@5628 1061 assert(nm != NULL, "invalid nmethod_pc");
roland@5628 1062 RelocIterator mds(nm, copy_buff, copy_buff + 1);
roland@5628 1063 bool found = false;
roland@5628 1064 while (mds.next() && !found) {
roland@5628 1065 if (mds.type() == relocInfo::oop_type) {
roland@5628 1066 assert(stub_id == Runtime1::load_mirror_patching_id ||
roland@5628 1067 stub_id == Runtime1::load_appendix_patching_id, "wrong stub id");
roland@5628 1068 oop_Relocation* r = mds.oop_reloc();
roland@5628 1069 oop* oop_adr = r->oop_addr();
roland@5628 1070 *oop_adr = stub_id == Runtime1::load_mirror_patching_id ? mirror() : appendix();
roland@5628 1071 r->fix_oop_relocation();
roland@5628 1072 found = true;
roland@5628 1073 } else if (mds.type() == relocInfo::metadata_type) {
roland@5628 1074 assert(stub_id == Runtime1::load_klass_patching_id, "wrong stub id");
roland@5628 1075 metadata_Relocation* r = mds.metadata_reloc();
roland@5628 1076 Metadata** metadata_adr = r->metadata_addr();
roland@5628 1077 *metadata_adr = load_klass();
roland@5628 1078 r->fix_metadata_relocation();
roland@5628 1079 found = true;
roland@5628 1080 }
roland@5628 1081 }
roland@5628 1082 assert(found, "the metadata must exist!");
roland@5628 1083 }
roland@5628 1084 #endif
duke@435 1085 if (do_patch) {
duke@435 1086 // replace instructions
duke@435 1087 // first replace the tail, then the call
bobv@2036 1088 #ifdef ARM
jiangli@5803 1089 if((load_klass_or_mirror_patch_id ||
jiangli@5803 1090 stub_id == Runtime1::load_appendix_patching_id) &&
dlong@7598 1091 nativeMovConstReg_at(copy_buff)->is_pc_relative()) {
vladidan@2801 1092 nmethod* nm = CodeCache::find_nmethod(instr_pc);
coleenp@4037 1093 address addr = NULL;
vladidan@2801 1094 assert(nm != NULL, "invalid nmethod_pc");
coleenp@4037 1095 RelocIterator mds(nm, copy_buff, copy_buff + 1);
coleenp@4037 1096 while (mds.next()) {
coleenp@4037 1097 if (mds.type() == relocInfo::oop_type) {
jiangli@5803 1098 assert(stub_id == Runtime1::load_mirror_patching_id ||
jiangli@5803 1099 stub_id == Runtime1::load_appendix_patching_id, "wrong stub id");
coleenp@4037 1100 oop_Relocation* r = mds.oop_reloc();
coleenp@4037 1101 addr = (address)r->oop_addr();
coleenp@4037 1102 break;
coleenp@4037 1103 } else if (mds.type() == relocInfo::metadata_type) {
coleenp@4037 1104 assert(stub_id == Runtime1::load_klass_patching_id, "wrong stub id");
coleenp@4037 1105 metadata_Relocation* r = mds.metadata_reloc();
coleenp@4037 1106 addr = (address)r->metadata_addr();
vladidan@2801 1107 break;
vladidan@2801 1108 }
vladidan@2801 1109 }
coleenp@4037 1110 assert(addr != NULL, "metadata relocation must exist");
bobv@2036 1111 copy_buff -= *byte_count;
bobv@2036 1112 NativeMovConstReg* n_copy2 = nativeMovConstReg_at(copy_buff);
coleenp@4037 1113 n_copy2->set_pc_relative_offset(addr, instr_pc);
bobv@2036 1114 }
bobv@2036 1115 #endif
bobv@2036 1116
duke@435 1117 for (int i = NativeCall::instruction_size; i < *byte_count; i++) {
duke@435 1118 address ptr = copy_buff + i;
duke@435 1119 int a_byte = (*ptr) & 0xFF;
duke@435 1120 address dst = instr_pc + i;
duke@435 1121 *(unsigned char*)dst = (unsigned char) a_byte;
duke@435 1122 }
duke@435 1123 ICache::invalidate_range(instr_pc, *byte_count);
duke@435 1124 NativeGeneralJump::replace_mt_safe(instr_pc, copy_buff);
duke@435 1125
roland@5628 1126 if (load_klass_or_mirror_patch_id ||
roland@5628 1127 stub_id == Runtime1::load_appendix_patching_id) {
coleenp@4037 1128 relocInfo::relocType rtype =
coleenp@4037 1129 (stub_id == Runtime1::load_klass_patching_id) ?
coleenp@4037 1130 relocInfo::metadata_type :
coleenp@4037 1131 relocInfo::oop_type;
coleenp@4037 1132 // update relocInfo to metadata
duke@435 1133 nmethod* nm = CodeCache::find_nmethod(instr_pc);
duke@435 1134 assert(nm != NULL, "invalid nmethod_pc");
duke@435 1135
duke@435 1136 // The old patch site is now a move instruction so update
duke@435 1137 // the reloc info so that it will get updated during
duke@435 1138 // future GCs.
duke@435 1139 RelocIterator iter(nm, (address)instr_pc, (address)(instr_pc + 1));
duke@435 1140 relocInfo::change_reloc_info_for_address(&iter, (address) instr_pc,
coleenp@4037 1141 relocInfo::none, rtype);
duke@435 1142 #ifdef SPARC
coleenp@4037 1143 // Sparc takes two relocations for an metadata so update the second one.
duke@435 1144 address instr_pc2 = instr_pc + NativeMovConstReg::add_offset;
duke@435 1145 RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1);
duke@435 1146 relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2,
coleenp@4037 1147 relocInfo::none, rtype);
duke@435 1148 #endif
bobv@2036 1149 #ifdef PPC
bobv@2036 1150 { address instr_pc2 = instr_pc + NativeMovConstReg::lo_offset;
bobv@2036 1151 RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1);
coleenp@4037 1152 relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2,
coleenp@4037 1153 relocInfo::none, rtype);
bobv@2036 1154 }
bobv@2036 1155 #endif
duke@435 1156 }
duke@435 1157
duke@435 1158 } else {
duke@435 1159 ICache::invalidate_range(copy_buff, *byte_count);
duke@435 1160 NativeGeneralJump::insert_unconditional(instr_pc, being_initialized_entry);
duke@435 1161 }
duke@435 1162 }
duke@435 1163 }
duke@435 1164 }
johnc@5548 1165
johnc@5548 1166 // If we are patching in a non-perm oop, make sure the nmethod
johnc@5548 1167 // is on the right list.
roland@5628 1168 if (ScavengeRootsInCode && ((mirror.not_null() && mirror()->is_scavengable()) ||
roland@5628 1169 (appendix.not_null() && appendix->is_scavengable()))) {
johnc@5548 1170 MutexLockerEx ml_code (CodeCache_lock, Mutex::_no_safepoint_check_flag);
johnc@5548 1171 nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
johnc@5548 1172 guarantee(nm != NULL, "only nmethods can contain non-perm oops");
johnc@5548 1173 if (!nm->on_scavenge_root_list()) {
johnc@5548 1174 CodeCache::add_scavenge_root_nmethod(nm);
johnc@5548 1175 }
johnc@5548 1176
johnc@5548 1177 // Since we've patched some oops in the nmethod,
johnc@5548 1178 // (re)register it with the heap.
johnc@5548 1179 Universe::heap()->register_nmethod(nm);
johnc@5548 1180 }
duke@435 1181 JRT_END
duke@435 1182
duke@435 1183 //
duke@435 1184 // Entry point for compiled code. We want to patch a nmethod.
duke@435 1185 // We don't do a normal VM transition here because we want to
duke@435 1186 // know after the patching is complete and any safepoint(s) are taken
duke@435 1187 // if the calling nmethod was deoptimized. We do this by calling a
duke@435 1188 // helper method which does the normal VM transition and when it
duke@435 1189 // completes we can check for deoptimization. This simplifies the
duke@435 1190 // assembly code in the cpu directories.
duke@435 1191 //
duke@435 1192 int Runtime1::move_klass_patching(JavaThread* thread) {
duke@435 1193 //
duke@435 1194 // NOTE: we are still in Java
duke@435 1195 //
duke@435 1196 Thread* THREAD = thread;
duke@435 1197 debug_only(NoHandleMark nhm;)
duke@435 1198 {
duke@435 1199 // Enter VM mode
duke@435 1200
duke@435 1201 ResetNoHandleMark rnhm;
duke@435 1202 patch_code(thread, load_klass_patching_id);
duke@435 1203 }
duke@435 1204 // Back in JAVA, use no oops DON'T safepoint
duke@435 1205
duke@435 1206 // Return true if calling code is deoptimized
duke@435 1207
duke@435 1208 return caller_is_deopted();
duke@435 1209 }
duke@435 1210
coleenp@4037 1211 int Runtime1::move_mirror_patching(JavaThread* thread) {
coleenp@4037 1212 //
coleenp@4037 1213 // NOTE: we are still in Java
coleenp@4037 1214 //
coleenp@4037 1215 Thread* THREAD = thread;
coleenp@4037 1216 debug_only(NoHandleMark nhm;)
coleenp@4037 1217 {
coleenp@4037 1218 // Enter VM mode
coleenp@4037 1219
coleenp@4037 1220 ResetNoHandleMark rnhm;
coleenp@4037 1221 patch_code(thread, load_mirror_patching_id);
coleenp@4037 1222 }
coleenp@4037 1223 // Back in JAVA, use no oops DON'T safepoint
coleenp@4037 1224
coleenp@4037 1225 // Return true if calling code is deoptimized
coleenp@4037 1226
coleenp@4037 1227 return caller_is_deopted();
coleenp@4037 1228 }
coleenp@4037 1229
roland@5628 1230 int Runtime1::move_appendix_patching(JavaThread* thread) {
roland@5628 1231 //
roland@5628 1232 // NOTE: we are still in Java
roland@5628 1233 //
roland@5628 1234 Thread* THREAD = thread;
roland@5628 1235 debug_only(NoHandleMark nhm;)
roland@5628 1236 {
roland@5628 1237 // Enter VM mode
roland@5628 1238
roland@5628 1239 ResetNoHandleMark rnhm;
roland@5628 1240 patch_code(thread, load_appendix_patching_id);
roland@5628 1241 }
roland@5628 1242 // Back in JAVA, use no oops DON'T safepoint
roland@5628 1243
roland@5628 1244 // Return true if calling code is deoptimized
roland@5628 1245
roland@5628 1246 return caller_is_deopted();
roland@5628 1247 }
duke@435 1248 //
duke@435 1249 // Entry point for compiled code. We want to patch a nmethod.
duke@435 1250 // We don't do a normal VM transition here because we want to
duke@435 1251 // know after the patching is complete and any safepoint(s) are taken
duke@435 1252 // if the calling nmethod was deoptimized. We do this by calling a
duke@435 1253 // helper method which does the normal VM transition and when it
duke@435 1254 // completes we can check for deoptimization. This simplifies the
duke@435 1255 // assembly code in the cpu directories.
duke@435 1256 //
duke@435 1257
duke@435 1258 int Runtime1::access_field_patching(JavaThread* thread) {
duke@435 1259 //
duke@435 1260 // NOTE: we are still in Java
duke@435 1261 //
duke@435 1262 Thread* THREAD = thread;
duke@435 1263 debug_only(NoHandleMark nhm;)
duke@435 1264 {
duke@435 1265 // Enter VM mode
duke@435 1266
duke@435 1267 ResetNoHandleMark rnhm;
duke@435 1268 patch_code(thread, access_field_patching_id);
duke@435 1269 }
duke@435 1270 // Back in JAVA, use no oops DON'T safepoint
duke@435 1271
duke@435 1272 // Return true if calling code is deoptimized
duke@435 1273
duke@435 1274 return caller_is_deopted();
duke@435 1275 JRT_END
duke@435 1276
duke@435 1277
duke@435 1278 JRT_LEAF(void, Runtime1::trace_block_entry(jint block_id))
duke@435 1279 // for now we just print out the block id
duke@435 1280 tty->print("%d ", block_id);
duke@435 1281 JRT_END
duke@435 1282
duke@435 1283
coleenp@548 1284 // Array copy return codes.
coleenp@548 1285 enum {
coleenp@548 1286 ac_failed = -1, // arraycopy failed
coleenp@548 1287 ac_ok = 0 // arraycopy succeeded
coleenp@548 1288 };
coleenp@548 1289
coleenp@548 1290
ysr@1680 1291 // Below length is the # elements copied.
coleenp@548 1292 template <class T> int obj_arraycopy_work(oopDesc* src, T* src_addr,
coleenp@548 1293 oopDesc* dst, T* dst_addr,
coleenp@548 1294 int length) {
coleenp@548 1295
coleenp@548 1296 // For performance reasons, we assume we are using a card marking write
coleenp@548 1297 // barrier. The assert will fail if this is not the case.
coleenp@548 1298 // Note that we use the non-virtual inlineable variant of write_ref_array.
coleenp@548 1299 BarrierSet* bs = Universe::heap()->barrier_set();
ysr@1680 1300 assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
ysr@1680 1301 assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
coleenp@548 1302 if (src == dst) {
coleenp@548 1303 // same object, no check
ysr@1680 1304 bs->write_ref_array_pre(dst_addr, length);
coleenp@548 1305 Copy::conjoint_oops_atomic(src_addr, dst_addr, length);
ysr@1680 1306 bs->write_ref_array((HeapWord*)dst_addr, length);
coleenp@548 1307 return ac_ok;
coleenp@548 1308 } else {
coleenp@4142 1309 Klass* bound = ObjArrayKlass::cast(dst->klass())->element_klass();
coleenp@4142 1310 Klass* stype = ObjArrayKlass::cast(src->klass())->element_klass();
hseigel@4278 1311 if (stype == bound || stype->is_subtype_of(bound)) {
coleenp@548 1312 // Elements are guaranteed to be subtypes, so no check necessary
ysr@1680 1313 bs->write_ref_array_pre(dst_addr, length);
coleenp@548 1314 Copy::conjoint_oops_atomic(src_addr, dst_addr, length);
ysr@1680 1315 bs->write_ref_array((HeapWord*)dst_addr, length);
coleenp@548 1316 return ac_ok;
coleenp@548 1317 }
coleenp@548 1318 }
coleenp@548 1319 return ac_failed;
coleenp@548 1320 }
coleenp@548 1321
duke@435 1322 // fast and direct copy of arrays; returning -1, means that an exception may be thrown
duke@435 1323 // and we did not copy anything
duke@435 1324 JRT_LEAF(int, Runtime1::arraycopy(oopDesc* src, int src_pos, oopDesc* dst, int dst_pos, int length))
duke@435 1325 #ifndef PRODUCT
duke@435 1326 _generic_arraycopy_cnt++; // Slow-path oop array copy
duke@435 1327 #endif
duke@435 1328
duke@435 1329 if (src == NULL || dst == NULL || src_pos < 0 || dst_pos < 0 || length < 0) return ac_failed;
duke@435 1330 if (!dst->is_array() || !src->is_array()) return ac_failed;
duke@435 1331 if ((unsigned int) arrayOop(src)->length() < (unsigned int)src_pos + (unsigned int)length) return ac_failed;
duke@435 1332 if ((unsigned int) arrayOop(dst)->length() < (unsigned int)dst_pos + (unsigned int)length) return ac_failed;
duke@435 1333
duke@435 1334 if (length == 0) return ac_ok;
duke@435 1335 if (src->is_typeArray()) {
minqi@5097 1336 Klass* klass_oop = src->klass();
duke@435 1337 if (klass_oop != dst->klass()) return ac_failed;
coleenp@4142 1338 TypeArrayKlass* klass = TypeArrayKlass::cast(klass_oop);
duke@435 1339 const int l2es = klass->log2_element_size();
duke@435 1340 const int ihs = klass->array_header_in_bytes() / wordSize;
duke@435 1341 char* src_addr = (char*) ((oopDesc**)src + ihs) + (src_pos << l2es);
duke@435 1342 char* dst_addr = (char*) ((oopDesc**)dst + ihs) + (dst_pos << l2es);
duke@435 1343 // Potential problem: memmove is not guaranteed to be word atomic
duke@435 1344 // Revisit in Merlin
duke@435 1345 memmove(dst_addr, src_addr, length << l2es);
duke@435 1346 return ac_ok;
duke@435 1347 } else if (src->is_objArray() && dst->is_objArray()) {
iveresov@2344 1348 if (UseCompressedOops) {
coleenp@548 1349 narrowOop *src_addr = objArrayOop(src)->obj_at_addr<narrowOop>(src_pos);
coleenp@548 1350 narrowOop *dst_addr = objArrayOop(dst)->obj_at_addr<narrowOop>(dst_pos);
coleenp@548 1351 return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
duke@435 1352 } else {
coleenp@548 1353 oop *src_addr = objArrayOop(src)->obj_at_addr<oop>(src_pos);
coleenp@548 1354 oop *dst_addr = objArrayOop(dst)->obj_at_addr<oop>(dst_pos);
coleenp@548 1355 return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
duke@435 1356 }
duke@435 1357 }
duke@435 1358 return ac_failed;
duke@435 1359 JRT_END
duke@435 1360
duke@435 1361
duke@435 1362 JRT_LEAF(void, Runtime1::primitive_arraycopy(HeapWord* src, HeapWord* dst, int length))
duke@435 1363 #ifndef PRODUCT
duke@435 1364 _primitive_arraycopy_cnt++;
duke@435 1365 #endif
duke@435 1366
duke@435 1367 if (length == 0) return;
duke@435 1368 // Not guaranteed to be word atomic, but that doesn't matter
duke@435 1369 // for anything but an oop array, which is covered by oop_arraycopy.
kvn@1958 1370 Copy::conjoint_jbytes(src, dst, length);
duke@435 1371 JRT_END
duke@435 1372
duke@435 1373 JRT_LEAF(void, Runtime1::oop_arraycopy(HeapWord* src, HeapWord* dst, int num))
duke@435 1374 #ifndef PRODUCT
duke@435 1375 _oop_arraycopy_cnt++;
duke@435 1376 #endif
duke@435 1377
duke@435 1378 if (num == 0) return;
ysr@1680 1379 BarrierSet* bs = Universe::heap()->barrier_set();
ysr@1680 1380 assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
ysr@1680 1381 assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
ysr@1680 1382 if (UseCompressedOops) {
ysr@1680 1383 bs->write_ref_array_pre((narrowOop*)dst, num);
iveresov@2344 1384 Copy::conjoint_oops_atomic((narrowOop*) src, (narrowOop*) dst, num);
ysr@1680 1385 } else {
ysr@1680 1386 bs->write_ref_array_pre((oop*)dst, num);
iveresov@2344 1387 Copy::conjoint_oops_atomic((oop*) src, (oop*) dst, num);
ysr@1680 1388 }
ysr@1680 1389 bs->write_ref_array(dst, num);
duke@435 1390 JRT_END
duke@435 1391
duke@435 1392
roland@3838 1393 JRT_LEAF(int, Runtime1::is_instance_of(oopDesc* mirror, oopDesc* obj))
roland@3838 1394 // had to return int instead of bool, otherwise there may be a mismatch
roland@3838 1395 // between the C calling convention and the Java one.
roland@3838 1396 // e.g., on x86, GCC may clear only %al when returning a bool false, but
roland@3838 1397 // JVM takes the whole %eax as the return value, which may misinterpret
roland@3838 1398 // the return value as a boolean true.
roland@3838 1399
roland@3838 1400 assert(mirror != NULL, "should null-check on mirror before calling");
coleenp@4037 1401 Klass* k = java_lang_Class::as_Klass(mirror);
roland@3838 1402 return (k != NULL && obj != NULL && obj->is_a(k)) ? 1 : 0;
roland@3838 1403 JRT_END
roland@3838 1404
roland@4860 1405 JRT_ENTRY(void, Runtime1::predicate_failed_trap(JavaThread* thread))
roland@4860 1406 ResourceMark rm;
roland@4860 1407
roland@4860 1408 assert(!TieredCompilation, "incompatible with tiered compilation");
roland@4860 1409
roland@4860 1410 RegisterMap reg_map(thread, false);
roland@4860 1411 frame runtime_frame = thread->last_frame();
roland@4860 1412 frame caller_frame = runtime_frame.sender(&reg_map);
roland@4860 1413
roland@4860 1414 nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
roland@4860 1415 assert (nm != NULL, "no more nmethod?");
roland@4860 1416 nm->make_not_entrant();
roland@4860 1417
roland@4860 1418 methodHandle m(nm->method());
roland@4860 1419 MethodData* mdo = m->method_data();
roland@4860 1420
roland@4860 1421 if (mdo == NULL && !HAS_PENDING_EXCEPTION) {
roland@4860 1422 // Build an MDO. Ignore errors like OutOfMemory;
roland@4860 1423 // that simply means we won't have an MDO to update.
roland@4860 1424 Method::build_interpreter_method_data(m, THREAD);
roland@4860 1425 if (HAS_PENDING_EXCEPTION) {
roland@4860 1426 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
roland@4860 1427 CLEAR_PENDING_EXCEPTION;
roland@4860 1428 }
roland@4860 1429 mdo = m->method_data();
roland@4860 1430 }
roland@4860 1431
roland@4860 1432 if (mdo != NULL) {
roland@4860 1433 mdo->inc_trap_count(Deoptimization::Reason_none);
roland@4860 1434 }
roland@4860 1435
roland@4860 1436 if (TracePredicateFailedTraps) {
roland@4860 1437 stringStream ss1, ss2;
roland@4860 1438 vframeStream vfst(thread);
roland@4860 1439 methodHandle inlinee = methodHandle(vfst.method());
roland@4860 1440 inlinee->print_short_name(&ss1);
roland@4860 1441 m->print_short_name(&ss2);
drchase@6680 1442 tty->print_cr("Predicate failed trap in method %s at bci %d inlined in %s at pc " INTPTR_FORMAT, ss1.as_string(), vfst.bci(), ss2.as_string(), p2i(caller_frame.pc()));
roland@4860 1443 }
roland@4860 1444
roland@4860 1445
roland@4860 1446 Deoptimization::deoptimize_frame(thread, caller_frame.id());
roland@4860 1447
roland@4860 1448 JRT_END
roland@3838 1449
duke@435 1450 #ifndef PRODUCT
duke@435 1451 void Runtime1::print_statistics() {
duke@435 1452 tty->print_cr("C1 Runtime statistics:");
duke@435 1453 tty->print_cr(" _resolve_invoke_virtual_cnt: %d", SharedRuntime::_resolve_virtual_ctr);
duke@435 1454 tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %d", SharedRuntime::_resolve_opt_virtual_ctr);
duke@435 1455 tty->print_cr(" _resolve_invoke_static_cnt: %d", SharedRuntime::_resolve_static_ctr);
duke@435 1456 tty->print_cr(" _handle_wrong_method_cnt: %d", SharedRuntime::_wrong_method_ctr);
duke@435 1457 tty->print_cr(" _ic_miss_cnt: %d", SharedRuntime::_ic_miss_ctr);
duke@435 1458 tty->print_cr(" _generic_arraycopy_cnt: %d", _generic_arraycopy_cnt);
roland@2728 1459 tty->print_cr(" _generic_arraycopystub_cnt: %d", _generic_arraycopystub_cnt);
roland@2728 1460 tty->print_cr(" _byte_arraycopy_cnt: %d", _byte_arraycopy_cnt);
roland@2728 1461 tty->print_cr(" _short_arraycopy_cnt: %d", _short_arraycopy_cnt);
roland@2728 1462 tty->print_cr(" _int_arraycopy_cnt: %d", _int_arraycopy_cnt);
roland@2728 1463 tty->print_cr(" _long_arraycopy_cnt: %d", _long_arraycopy_cnt);
duke@435 1464 tty->print_cr(" _primitive_arraycopy_cnt: %d", _primitive_arraycopy_cnt);
roland@2728 1465 tty->print_cr(" _oop_arraycopy_cnt (C): %d", Runtime1::_oop_arraycopy_cnt);
roland@2728 1466 tty->print_cr(" _oop_arraycopy_cnt (stub): %d", _oop_arraycopy_cnt);
duke@435 1467 tty->print_cr(" _arraycopy_slowcase_cnt: %d", _arraycopy_slowcase_cnt);
roland@2728 1468 tty->print_cr(" _arraycopy_checkcast_cnt: %d", _arraycopy_checkcast_cnt);
roland@2728 1469 tty->print_cr(" _arraycopy_checkcast_attempt_cnt:%d", _arraycopy_checkcast_attempt_cnt);
duke@435 1470
duke@435 1471 tty->print_cr(" _new_type_array_slowcase_cnt: %d", _new_type_array_slowcase_cnt);
duke@435 1472 tty->print_cr(" _new_object_array_slowcase_cnt: %d", _new_object_array_slowcase_cnt);
duke@435 1473 tty->print_cr(" _new_instance_slowcase_cnt: %d", _new_instance_slowcase_cnt);
duke@435 1474 tty->print_cr(" _new_multi_array_slowcase_cnt: %d", _new_multi_array_slowcase_cnt);
duke@435 1475 tty->print_cr(" _monitorenter_slowcase_cnt: %d", _monitorenter_slowcase_cnt);
duke@435 1476 tty->print_cr(" _monitorexit_slowcase_cnt: %d", _monitorexit_slowcase_cnt);
duke@435 1477 tty->print_cr(" _patch_code_slowcase_cnt: %d", _patch_code_slowcase_cnt);
duke@435 1478
duke@435 1479 tty->print_cr(" _throw_range_check_exception_count: %d:", _throw_range_check_exception_count);
duke@435 1480 tty->print_cr(" _throw_index_exception_count: %d:", _throw_index_exception_count);
duke@435 1481 tty->print_cr(" _throw_div0_exception_count: %d:", _throw_div0_exception_count);
duke@435 1482 tty->print_cr(" _throw_null_pointer_exception_count: %d:", _throw_null_pointer_exception_count);
duke@435 1483 tty->print_cr(" _throw_class_cast_exception_count: %d:", _throw_class_cast_exception_count);
duke@435 1484 tty->print_cr(" _throw_incompatible_class_change_error_count: %d:", _throw_incompatible_class_change_error_count);
duke@435 1485 tty->print_cr(" _throw_array_store_exception_count: %d:", _throw_array_store_exception_count);
duke@435 1486 tty->print_cr(" _throw_count: %d:", _throw_count);
duke@435 1487
duke@435 1488 SharedRuntime::print_ic_miss_histogram();
duke@435 1489 tty->cr();
duke@435 1490 }
duke@435 1491 #endif // PRODUCT

mercurial