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