src/share/vm/runtime/deoptimization.cpp

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 10026
8c95980d0b66
parent 9448
73d689add964
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f

aoqi@0 1 /*
kevinw@8395 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@1 25 /*
aoqi@1 26 * This file has been modified by Loongson Technology in 2015. These
aoqi@1 27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
aoqi@1 28 * available on the same license terms set forth above.
aoqi@1 29 */
aoqi@1 30
aoqi@0 31 #include "precompiled.hpp"
aoqi@0 32 #include "classfile/systemDictionary.hpp"
aoqi@0 33 #include "code/debugInfoRec.hpp"
aoqi@0 34 #include "code/nmethod.hpp"
aoqi@0 35 #include "code/pcDesc.hpp"
aoqi@0 36 #include "code/scopeDesc.hpp"
aoqi@0 37 #include "interpreter/bytecode.hpp"
aoqi@0 38 #include "interpreter/interpreter.hpp"
aoqi@0 39 #include "interpreter/oopMapCache.hpp"
aoqi@0 40 #include "memory/allocation.inline.hpp"
aoqi@0 41 #include "memory/oopFactory.hpp"
aoqi@0 42 #include "memory/resourceArea.hpp"
aoqi@0 43 #include "oops/method.hpp"
aoqi@0 44 #include "oops/oop.inline.hpp"
aoqi@0 45 #include "prims/jvmtiThreadState.hpp"
aoqi@0 46 #include "runtime/biasedLocking.hpp"
aoqi@0 47 #include "runtime/compilationPolicy.hpp"
aoqi@0 48 #include "runtime/deoptimization.hpp"
aoqi@0 49 #include "runtime/interfaceSupport.hpp"
aoqi@0 50 #include "runtime/sharedRuntime.hpp"
aoqi@0 51 #include "runtime/signature.hpp"
aoqi@0 52 #include "runtime/stubRoutines.hpp"
aoqi@0 53 #include "runtime/thread.hpp"
aoqi@0 54 #include "runtime/vframe.hpp"
aoqi@0 55 #include "runtime/vframeArray.hpp"
aoqi@0 56 #include "runtime/vframe_hp.hpp"
aoqi@0 57 #include "utilities/events.hpp"
aoqi@0 58 #include "utilities/xmlstream.hpp"
aoqi@0 59 #ifdef TARGET_ARCH_x86
aoqi@0 60 # include "vmreg_x86.inline.hpp"
aoqi@0 61 #endif
aoqi@0 62 #ifdef TARGET_ARCH_sparc
aoqi@0 63 # include "vmreg_sparc.inline.hpp"
aoqi@0 64 #endif
aoqi@0 65 #ifdef TARGET_ARCH_zero
aoqi@0 66 # include "vmreg_zero.inline.hpp"
aoqi@0 67 #endif
aoqi@0 68 #ifdef TARGET_ARCH_arm
aoqi@0 69 # include "vmreg_arm.inline.hpp"
aoqi@0 70 #endif
aoqi@0 71 #ifdef TARGET_ARCH_ppc
aoqi@0 72 # include "vmreg_ppc.inline.hpp"
aoqi@0 73 #endif
aoqi@1 74 #ifdef TARGET_ARCH_mips
aoqi@1 75 # include "vmreg_mips.inline.hpp"
aoqi@1 76 #endif
aoqi@0 77 #ifdef COMPILER2
dlong@7598 78 #if defined AD_MD_HPP
dlong@7598 79 # include AD_MD_HPP
dlong@7598 80 #elif defined TARGET_ARCH_MODEL_x86_32
aoqi@0 81 # include "adfiles/ad_x86_32.hpp"
dlong@7598 82 #elif defined TARGET_ARCH_MODEL_x86_64
aoqi@0 83 # include "adfiles/ad_x86_64.hpp"
dlong@7598 84 #elif defined TARGET_ARCH_MODEL_sparc
aoqi@0 85 # include "adfiles/ad_sparc.hpp"
dlong@7598 86 #elif defined TARGET_ARCH_MODEL_zero
aoqi@0 87 # include "adfiles/ad_zero.hpp"
dlong@7598 88 #elif defined TARGET_ARCH_MODEL_ppc_64
aoqi@0 89 # include "adfiles/ad_ppc_64.hpp"
aoqi@0 90 #endif
aoqi@1 91 #ifdef TARGET_ARCH_MODEL_mips_64
aoqi@1 92 # include "adfiles/ad_mips_64.hpp"
aoqi@1 93 #endif
aoqi@0 94 #endif // COMPILER2
aoqi@0 95
aoqi@0 96 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 97
aoqi@0 98 bool DeoptimizationMarker::_is_active = false;
aoqi@0 99
aoqi@0 100 Deoptimization::UnrollBlock::UnrollBlock(int size_of_deoptimized_frame,
aoqi@0 101 int caller_adjustment,
aoqi@0 102 int caller_actual_parameters,
aoqi@0 103 int number_of_frames,
aoqi@0 104 intptr_t* frame_sizes,
aoqi@0 105 address* frame_pcs,
aoqi@0 106 BasicType return_type) {
aoqi@0 107 _size_of_deoptimized_frame = size_of_deoptimized_frame;
aoqi@0 108 _caller_adjustment = caller_adjustment;
aoqi@0 109 _caller_actual_parameters = caller_actual_parameters;
aoqi@0 110 _number_of_frames = number_of_frames;
aoqi@0 111 _frame_sizes = frame_sizes;
aoqi@0 112 _frame_pcs = frame_pcs;
aoqi@0 113 _register_block = NEW_C_HEAP_ARRAY(intptr_t, RegisterMap::reg_count * 2, mtCompiler);
aoqi@0 114 _return_type = return_type;
aoqi@0 115 _initial_info = 0;
aoqi@0 116 // PD (x86 only)
aoqi@0 117 _counter_temp = 0;
aoqi@0 118 _unpack_kind = 0;
aoqi@0 119 _sender_sp_temp = 0;
aoqi@0 120
aoqi@0 121 _total_frame_sizes = size_of_frames();
aoqi@0 122 }
aoqi@0 123
aoqi@0 124
aoqi@0 125 Deoptimization::UnrollBlock::~UnrollBlock() {
aoqi@0 126 FREE_C_HEAP_ARRAY(intptr_t, _frame_sizes, mtCompiler);
aoqi@0 127 FREE_C_HEAP_ARRAY(intptr_t, _frame_pcs, mtCompiler);
aoqi@0 128 FREE_C_HEAP_ARRAY(intptr_t, _register_block, mtCompiler);
aoqi@0 129 }
aoqi@0 130
aoqi@0 131
aoqi@0 132 intptr_t* Deoptimization::UnrollBlock::value_addr_at(int register_number) const {
aoqi@0 133 assert(register_number < RegisterMap::reg_count, "checking register number");
aoqi@0 134 return &_register_block[register_number * 2];
aoqi@0 135 }
aoqi@0 136
aoqi@0 137
aoqi@0 138
aoqi@0 139 int Deoptimization::UnrollBlock::size_of_frames() const {
aoqi@0 140 // Acount first for the adjustment of the initial frame
aoqi@0 141 int result = _caller_adjustment;
aoqi@0 142 for (int index = 0; index < number_of_frames(); index++) {
aoqi@0 143 result += frame_sizes()[index];
aoqi@0 144 }
aoqi@0 145 return result;
aoqi@0 146 }
aoqi@0 147
aoqi@0 148
aoqi@0 149 void Deoptimization::UnrollBlock::print() {
aoqi@0 150 ttyLocker ttyl;
aoqi@0 151 tty->print_cr("UnrollBlock");
aoqi@0 152 tty->print_cr(" size_of_deoptimized_frame = %d", _size_of_deoptimized_frame);
aoqi@0 153 tty->print( " frame_sizes: ");
aoqi@0 154 for (int index = 0; index < number_of_frames(); index++) {
aoqi@0 155 tty->print("%d ", frame_sizes()[index]);
aoqi@0 156 }
aoqi@0 157 tty->cr();
aoqi@0 158 }
aoqi@0 159
aoqi@0 160
aoqi@0 161 // In order to make fetch_unroll_info work properly with escape
aoqi@0 162 // analysis, The method was changed from JRT_LEAF to JRT_BLOCK_ENTRY and
aoqi@0 163 // ResetNoHandleMark and HandleMark were removed from it. The actual reallocation
aoqi@0 164 // of previously eliminated objects occurs in realloc_objects, which is
aoqi@0 165 // called from the method fetch_unroll_info_helper below.
aoqi@0 166 JRT_BLOCK_ENTRY(Deoptimization::UnrollBlock*, Deoptimization::fetch_unroll_info(JavaThread* thread))
aoqi@0 167 // It is actually ok to allocate handles in a leaf method. It causes no safepoints,
aoqi@0 168 // but makes the entry a little slower. There is however a little dance we have to
aoqi@0 169 // do in debug mode to get around the NoHandleMark code in the JRT_LEAF macro
aoqi@0 170
aoqi@0 171 // fetch_unroll_info() is called at the beginning of the deoptimization
aoqi@0 172 // handler. Note this fact before we start generating temporary frames
aoqi@0 173 // that can confuse an asynchronous stack walker. This counter is
aoqi@0 174 // decremented at the end of unpack_frames().
aoqi@0 175 thread->inc_in_deopt_handler();
aoqi@0 176
aoqi@0 177 return fetch_unroll_info_helper(thread);
aoqi@0 178 JRT_END
aoqi@0 179
aoqi@0 180
aoqi@0 181 // This is factored, since it is both called from a JRT_LEAF (deoptimization) and a JRT_ENTRY (uncommon_trap)
aoqi@0 182 Deoptimization::UnrollBlock* Deoptimization::fetch_unroll_info_helper(JavaThread* thread) {
aoqi@0 183
aoqi@0 184 // Note: there is a safepoint safety issue here. No matter whether we enter
aoqi@0 185 // via vanilla deopt or uncommon trap we MUST NOT stop at a safepoint once
aoqi@0 186 // the vframeArray is created.
aoqi@0 187 //
aoqi@0 188
aoqi@0 189 // Allocate our special deoptimization ResourceMark
aoqi@0 190 DeoptResourceMark* dmark = new DeoptResourceMark(thread);
aoqi@0 191 assert(thread->deopt_mark() == NULL, "Pending deopt!");
aoqi@0 192 thread->set_deopt_mark(dmark);
aoqi@0 193
aoqi@0 194 frame stub_frame = thread->last_frame(); // Makes stack walkable as side effect
aoqi@0 195 RegisterMap map(thread, true);
aoqi@0 196 RegisterMap dummy_map(thread, false);
aoqi@0 197 // Now get the deoptee with a valid map
aoqi@0 198 frame deoptee = stub_frame.sender(&map);
aoqi@0 199 // Set the deoptee nmethod
aoqi@0 200 assert(thread->deopt_nmethod() == NULL, "Pending deopt!");
aoqi@0 201 thread->set_deopt_nmethod(deoptee.cb()->as_nmethod_or_null());
aoqi@0 202
aoqi@0 203 if (VerifyStack) {
aoqi@0 204 thread->validate_frame_layout();
aoqi@0 205 }
aoqi@0 206
aoqi@0 207 // Create a growable array of VFrames where each VFrame represents an inlined
aoqi@0 208 // Java frame. This storage is allocated with the usual system arena.
aoqi@0 209 assert(deoptee.is_compiled_frame(), "Wrong frame type");
aoqi@0 210 GrowableArray<compiledVFrame*>* chunk = new GrowableArray<compiledVFrame*>(10);
aoqi@0 211 vframe* vf = vframe::new_vframe(&deoptee, &map, thread);
aoqi@0 212 while (!vf->is_top()) {
aoqi@0 213 assert(vf->is_compiled_frame(), "Wrong frame type");
aoqi@0 214 chunk->push(compiledVFrame::cast(vf));
aoqi@0 215 vf = vf->sender();
aoqi@0 216 }
aoqi@0 217 assert(vf->is_compiled_frame(), "Wrong frame type");
aoqi@0 218 chunk->push(compiledVFrame::cast(vf));
aoqi@0 219
roland@7419 220 bool realloc_failures = false;
roland@7419 221
aoqi@0 222 #ifdef COMPILER2
aoqi@0 223 // Reallocate the non-escaping objects and restore their fields. Then
aoqi@0 224 // relock objects if synchronization on them was eliminated.
aoqi@0 225 if (DoEscapeAnalysis || EliminateNestedLocks) {
aoqi@0 226 if (EliminateAllocations) {
aoqi@0 227 assert (chunk->at(0)->scope() != NULL,"expect only compiled java frames");
aoqi@0 228 GrowableArray<ScopeValue*>* objects = chunk->at(0)->scope()->objects();
aoqi@0 229
aoqi@0 230 // The flag return_oop() indicates call sites which return oop
aoqi@0 231 // in compiled code. Such sites include java method calls,
aoqi@0 232 // runtime calls (for example, used to allocate new objects/arrays
aoqi@0 233 // on slow code path) and any other calls generated in compiled code.
aoqi@0 234 // It is not guaranteed that we can get such information here only
aoqi@0 235 // by analyzing bytecode in deoptimized frames. This is why this flag
aoqi@0 236 // is set during method compilation (see Compile::Process_OopMap_Node()).
roland@7168 237 // If the previous frame was popped, we don't have a result.
roland@7168 238 bool save_oop_result = chunk->at(0)->scope()->return_oop() && !thread->popframe_forcing_deopt_reexecution();
aoqi@0 239 Handle return_value;
aoqi@0 240 if (save_oop_result) {
aoqi@0 241 // Reallocation may trigger GC. If deoptimization happened on return from
aoqi@0 242 // call which returns oop we need to save it since it is not in oopmap.
aoqi@0 243 oop result = deoptee.saved_oop_result(&map);
aoqi@0 244 assert(result == NULL || result->is_oop(), "must be oop");
aoqi@0 245 return_value = Handle(thread, result);
aoqi@0 246 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
aoqi@0 247 if (TraceDeoptimization) {
aoqi@0 248 ttyLocker ttyl;
aoqi@0 249 tty->print_cr("SAVED OOP RESULT " INTPTR_FORMAT " in thread " INTPTR_FORMAT, (void *)result, thread);
aoqi@0 250 }
aoqi@0 251 }
aoqi@0 252 if (objects != NULL) {
aoqi@0 253 JRT_BLOCK
roland@7419 254 realloc_failures = realloc_objects(thread, &deoptee, objects, THREAD);
aoqi@0 255 JRT_END
roland@7419 256 reassign_fields(&deoptee, &map, objects, realloc_failures);
aoqi@0 257 #ifndef PRODUCT
aoqi@0 258 if (TraceDeoptimization) {
aoqi@0 259 ttyLocker ttyl;
aoqi@0 260 tty->print_cr("REALLOC OBJECTS in thread " INTPTR_FORMAT, thread);
roland@7420 261 print_objects(objects, realloc_failures);
aoqi@0 262 }
aoqi@0 263 #endif
aoqi@0 264 }
aoqi@0 265 if (save_oop_result) {
aoqi@0 266 // Restore result.
aoqi@0 267 deoptee.set_saved_oop_result(&map, return_value());
aoqi@0 268 }
aoqi@0 269 }
aoqi@0 270 if (EliminateLocks) {
aoqi@0 271 #ifndef PRODUCT
aoqi@0 272 bool first = true;
aoqi@0 273 #endif
aoqi@0 274 for (int i = 0; i < chunk->length(); i++) {
aoqi@0 275 compiledVFrame* cvf = chunk->at(i);
aoqi@0 276 assert (cvf->scope() != NULL,"expect only compiled java frames");
aoqi@0 277 GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
aoqi@0 278 if (monitors->is_nonempty()) {
roland@7419 279 relock_objects(monitors, thread, realloc_failures);
aoqi@0 280 #ifndef PRODUCT
aoqi@0 281 if (TraceDeoptimization) {
aoqi@0 282 ttyLocker ttyl;
aoqi@0 283 for (int j = 0; j < monitors->length(); j++) {
aoqi@0 284 MonitorInfo* mi = monitors->at(j);
aoqi@0 285 if (mi->eliminated()) {
aoqi@0 286 if (first) {
aoqi@0 287 first = false;
aoqi@0 288 tty->print_cr("RELOCK OBJECTS in thread " INTPTR_FORMAT, thread);
aoqi@0 289 }
roland@7419 290 if (mi->owner_is_scalar_replaced()) {
roland@7419 291 Klass* k = java_lang_Class::as_Klass(mi->owner_klass());
roland@7419 292 tty->print_cr(" failed reallocation for klass %s", k->external_name());
roland@7419 293 } else {
roland@7419 294 tty->print_cr(" object <" INTPTR_FORMAT "> locked", (void *)mi->owner());
roland@7419 295 }
aoqi@0 296 }
aoqi@0 297 }
aoqi@0 298 }
aoqi@0 299 #endif
aoqi@0 300 }
aoqi@0 301 }
aoqi@0 302 }
aoqi@0 303 }
aoqi@0 304 #endif // COMPILER2
aoqi@0 305 // Ensure that no safepoint is taken after pointers have been stored
aoqi@0 306 // in fields of rematerialized objects. If a safepoint occurs from here on
aoqi@0 307 // out the java state residing in the vframeArray will be missed.
aoqi@0 308 No_Safepoint_Verifier no_safepoint;
aoqi@0 309
roland@7419 310 vframeArray* array = create_vframeArray(thread, deoptee, &map, chunk, realloc_failures);
roland@7419 311 #ifdef COMPILER2
roland@7419 312 if (realloc_failures) {
roland@7419 313 pop_frames_failed_reallocs(thread, array);
roland@7419 314 }
roland@7419 315 #endif
aoqi@0 316
roland@7419 317 assert(thread->vframe_array_head() == NULL, "Pending deopt!");
aoqi@0 318 thread->set_vframe_array_head(array);
aoqi@0 319
aoqi@0 320 // Now that the vframeArray has been created if we have any deferred local writes
aoqi@0 321 // added by jvmti then we can free up that structure as the data is now in the
aoqi@0 322 // vframeArray
aoqi@0 323
aoqi@0 324 if (thread->deferred_locals() != NULL) {
aoqi@0 325 GrowableArray<jvmtiDeferredLocalVariableSet*>* list = thread->deferred_locals();
aoqi@0 326 int i = 0;
aoqi@0 327 do {
aoqi@0 328 // Because of inlining we could have multiple vframes for a single frame
aoqi@0 329 // and several of the vframes could have deferred writes. Find them all.
aoqi@0 330 if (list->at(i)->id() == array->original().id()) {
aoqi@0 331 jvmtiDeferredLocalVariableSet* dlv = list->at(i);
aoqi@0 332 list->remove_at(i);
aoqi@0 333 // individual jvmtiDeferredLocalVariableSet are CHeapObj's
aoqi@0 334 delete dlv;
aoqi@0 335 } else {
aoqi@0 336 i++;
aoqi@0 337 }
aoqi@0 338 } while ( i < list->length() );
aoqi@0 339 if (list->length() == 0) {
aoqi@0 340 thread->set_deferred_locals(NULL);
aoqi@0 341 // free the list and elements back to C heap.
aoqi@0 342 delete list;
aoqi@0 343 }
aoqi@0 344
aoqi@0 345 }
aoqi@0 346
aoqi@0 347 #ifndef SHARK
aoqi@0 348 // Compute the caller frame based on the sender sp of stub_frame and stored frame sizes info.
aoqi@0 349 CodeBlob* cb = stub_frame.cb();
aoqi@0 350 // Verify we have the right vframeArray
aoqi@0 351 assert(cb->frame_size() >= 0, "Unexpected frame size");
aoqi@0 352 intptr_t* unpack_sp = stub_frame.sp() + cb->frame_size();
aoqi@0 353
aoqi@0 354 // If the deopt call site is a MethodHandle invoke call site we have
aoqi@0 355 // to adjust the unpack_sp.
aoqi@0 356 nmethod* deoptee_nm = deoptee.cb()->as_nmethod_or_null();
aoqi@0 357 if (deoptee_nm != NULL && deoptee_nm->is_method_handle_return(deoptee.pc()))
aoqi@0 358 unpack_sp = deoptee.unextended_sp();
aoqi@0 359
aoqi@0 360 #ifdef ASSERT
aoqi@0 361 assert(cb->is_deoptimization_stub() || cb->is_uncommon_trap_stub(), "just checking");
aoqi@0 362 #endif
aoqi@0 363 #else
aoqi@0 364 intptr_t* unpack_sp = stub_frame.sender(&dummy_map).unextended_sp();
aoqi@0 365 #endif // !SHARK
aoqi@0 366
aoqi@0 367 // This is a guarantee instead of an assert because if vframe doesn't match
aoqi@0 368 // we will unpack the wrong deoptimized frame and wind up in strange places
aoqi@0 369 // where it will be very difficult to figure out what went wrong. Better
aoqi@0 370 // to die an early death here than some very obscure death later when the
aoqi@0 371 // trail is cold.
aoqi@0 372 // Note: on ia64 this guarantee can be fooled by frames with no memory stack
aoqi@0 373 // in that it will fail to detect a problem when there is one. This needs
aoqi@0 374 // more work in tiger timeframe.
aoqi@0 375 guarantee(array->unextended_sp() == unpack_sp, "vframe_array_head must contain the vframeArray to unpack");
aoqi@0 376
aoqi@0 377 int number_of_frames = array->frames();
aoqi@0 378
aoqi@0 379 // Compute the vframes' sizes. Note that frame_sizes[] entries are ordered from outermost to innermost
aoqi@0 380 // virtual activation, which is the reverse of the elements in the vframes array.
aoqi@0 381 intptr_t* frame_sizes = NEW_C_HEAP_ARRAY(intptr_t, number_of_frames, mtCompiler);
aoqi@0 382 // +1 because we always have an interpreter return address for the final slot.
aoqi@0 383 address* frame_pcs = NEW_C_HEAP_ARRAY(address, number_of_frames + 1, mtCompiler);
aoqi@0 384 int popframe_extra_args = 0;
aoqi@0 385 // Create an interpreter return address for the stub to use as its return
aoqi@0 386 // address so the skeletal frames are perfectly walkable
aoqi@0 387 frame_pcs[number_of_frames] = Interpreter::deopt_entry(vtos, 0);
aoqi@0 388
aoqi@0 389 // PopFrame requires that the preserved incoming arguments from the recently-popped topmost
aoqi@0 390 // activation be put back on the expression stack of the caller for reexecution
aoqi@0 391 if (JvmtiExport::can_pop_frame() && thread->popframe_forcing_deopt_reexecution()) {
aoqi@0 392 popframe_extra_args = in_words(thread->popframe_preserved_args_size_in_words());
aoqi@0 393 }
aoqi@0 394
aoqi@0 395 // Find the current pc for sender of the deoptee. Since the sender may have been deoptimized
aoqi@0 396 // itself since the deoptee vframeArray was created we must get a fresh value of the pc rather
aoqi@0 397 // than simply use array->sender.pc(). This requires us to walk the current set of frames
aoqi@0 398 //
aoqi@0 399 frame deopt_sender = stub_frame.sender(&dummy_map); // First is the deoptee frame
aoqi@0 400 deopt_sender = deopt_sender.sender(&dummy_map); // Now deoptee caller
aoqi@0 401
aoqi@0 402 // It's possible that the number of paramters at the call site is
aoqi@0 403 // different than number of arguments in the callee when method
aoqi@0 404 // handles are used. If the caller is interpreted get the real
aoqi@0 405 // value so that the proper amount of space can be added to it's
aoqi@0 406 // frame.
aoqi@0 407 bool caller_was_method_handle = false;
aoqi@0 408 if (deopt_sender.is_interpreted_frame()) {
aoqi@0 409 methodHandle method = deopt_sender.interpreter_frame_method();
aoqi@0 410 Bytecode_invoke cur = Bytecode_invoke_check(method, deopt_sender.interpreter_frame_bci());
aoqi@0 411 if (cur.is_invokedynamic() || cur.is_invokehandle()) {
aoqi@0 412 // Method handle invokes may involve fairly arbitrary chains of
aoqi@0 413 // calls so it's impossible to know how much actual space the
aoqi@0 414 // caller has for locals.
aoqi@0 415 caller_was_method_handle = true;
aoqi@0 416 }
aoqi@0 417 }
aoqi@0 418
aoqi@0 419 //
aoqi@0 420 // frame_sizes/frame_pcs[0] oldest frame (int or c2i)
aoqi@0 421 // frame_sizes/frame_pcs[1] next oldest frame (int)
aoqi@0 422 // frame_sizes/frame_pcs[n] youngest frame (int)
aoqi@0 423 //
aoqi@0 424 // Now a pc in frame_pcs is actually the return address to the frame's caller (a frame
aoqi@0 425 // owns the space for the return address to it's caller). Confusing ain't it.
aoqi@0 426 //
aoqi@0 427 // The vframe array can address vframes with indices running from
aoqi@0 428 // 0.._frames-1. Index 0 is the youngest frame and _frame - 1 is the oldest (root) frame.
aoqi@0 429 // When we create the skeletal frames we need the oldest frame to be in the zero slot
aoqi@0 430 // in the frame_sizes/frame_pcs so the assembly code can do a trivial walk.
aoqi@0 431 // so things look a little strange in this loop.
aoqi@0 432 //
aoqi@0 433 int callee_parameters = 0;
aoqi@0 434 int callee_locals = 0;
aoqi@0 435 for (int index = 0; index < array->frames(); index++ ) {
aoqi@0 436 // frame[number_of_frames - 1 ] = on_stack_size(youngest)
aoqi@0 437 // frame[number_of_frames - 2 ] = on_stack_size(sender(youngest))
aoqi@0 438 // frame[number_of_frames - 3 ] = on_stack_size(sender(sender(youngest)))
aoqi@0 439 frame_sizes[number_of_frames - 1 - index] = BytesPerWord * array->element(index)->on_stack_size(callee_parameters,
aoqi@0 440 callee_locals,
aoqi@0 441 index == 0,
aoqi@0 442 popframe_extra_args);
aoqi@0 443 // This pc doesn't have to be perfect just good enough to identify the frame
aoqi@0 444 // as interpreted so the skeleton frame will be walkable
aoqi@0 445 // The correct pc will be set when the skeleton frame is completely filled out
aoqi@0 446 // The final pc we store in the loop is wrong and will be overwritten below
aoqi@0 447 frame_pcs[number_of_frames - 1 - index ] = Interpreter::deopt_entry(vtos, 0) - frame::pc_return_offset;
aoqi@0 448
aoqi@0 449 callee_parameters = array->element(index)->method()->size_of_parameters();
aoqi@0 450 callee_locals = array->element(index)->method()->max_locals();
aoqi@0 451 popframe_extra_args = 0;
aoqi@0 452 }
aoqi@0 453
aoqi@0 454 // Compute whether the root vframe returns a float or double value.
aoqi@0 455 BasicType return_type;
aoqi@0 456 {
aoqi@0 457 HandleMark hm;
aoqi@0 458 methodHandle method(thread, array->element(0)->method());
aoqi@0 459 Bytecode_invoke invoke = Bytecode_invoke_check(method, array->element(0)->bci());
aoqi@0 460 return_type = invoke.is_valid() ? invoke.result_type() : T_ILLEGAL;
aoqi@0 461 }
aoqi@0 462
aoqi@0 463 // Compute information for handling adapters and adjusting the frame size of the caller.
aoqi@0 464 int caller_adjustment = 0;
aoqi@0 465
aoqi@0 466 // Compute the amount the oldest interpreter frame will have to adjust
aoqi@0 467 // its caller's stack by. If the caller is a compiled frame then
aoqi@0 468 // we pretend that the callee has no parameters so that the
aoqi@0 469 // extension counts for the full amount of locals and not just
aoqi@0 470 // locals-parms. This is because without a c2i adapter the parm
aoqi@0 471 // area as created by the compiled frame will not be usable by
aoqi@0 472 // the interpreter. (Depending on the calling convention there
aoqi@0 473 // may not even be enough space).
aoqi@0 474
aoqi@0 475 // QQQ I'd rather see this pushed down into last_frame_adjust
aoqi@0 476 // and have it take the sender (aka caller).
aoqi@0 477
aoqi@0 478 if (deopt_sender.is_compiled_frame() || caller_was_method_handle) {
aoqi@0 479 caller_adjustment = last_frame_adjust(0, callee_locals);
aoqi@0 480 } else if (callee_locals > callee_parameters) {
aoqi@0 481 // The caller frame may need extending to accommodate
aoqi@0 482 // non-parameter locals of the first unpacked interpreted frame.
aoqi@0 483 // Compute that adjustment.
aoqi@0 484 caller_adjustment = last_frame_adjust(callee_parameters, callee_locals);
aoqi@0 485 }
aoqi@0 486
aoqi@0 487 // If the sender is deoptimized the we must retrieve the address of the handler
aoqi@0 488 // since the frame will "magically" show the original pc before the deopt
aoqi@0 489 // and we'd undo the deopt.
aoqi@0 490
aoqi@0 491 frame_pcs[0] = deopt_sender.raw_pc();
aoqi@0 492
aoqi@0 493 #ifndef SHARK
aoqi@0 494 assert(CodeCache::find_blob_unsafe(frame_pcs[0]) != NULL, "bad pc");
aoqi@0 495 #endif // SHARK
aoqi@0 496
aoqi@0 497 UnrollBlock* info = new UnrollBlock(array->frame_size() * BytesPerWord,
aoqi@0 498 caller_adjustment * BytesPerWord,
aoqi@0 499 caller_was_method_handle ? 0 : callee_parameters,
aoqi@0 500 number_of_frames,
aoqi@0 501 frame_sizes,
aoqi@0 502 frame_pcs,
aoqi@0 503 return_type);
aoqi@0 504 // On some platforms, we need a way to pass some platform dependent
aoqi@0 505 // information to the unpacking code so the skeletal frames come out
aoqi@0 506 // correct (initial fp value, unextended sp, ...)
aoqi@0 507 info->set_initial_info((intptr_t) array->sender().initial_deoptimization_info());
aoqi@0 508
aoqi@0 509 if (array->frames() > 1) {
aoqi@0 510 if (VerifyStack && TraceDeoptimization) {
aoqi@0 511 ttyLocker ttyl;
aoqi@0 512 tty->print_cr("Deoptimizing method containing inlining");
aoqi@0 513 }
aoqi@0 514 }
aoqi@0 515
aoqi@0 516 array->set_unroll_block(info);
aoqi@0 517 return info;
aoqi@0 518 }
aoqi@0 519
aoqi@0 520 // Called to cleanup deoptimization data structures in normal case
aoqi@0 521 // after unpacking to stack and when stack overflow error occurs
aoqi@0 522 void Deoptimization::cleanup_deopt_info(JavaThread *thread,
aoqi@0 523 vframeArray *array) {
aoqi@0 524
aoqi@0 525 // Get array if coming from exception
aoqi@0 526 if (array == NULL) {
aoqi@0 527 array = thread->vframe_array_head();
aoqi@0 528 }
aoqi@0 529 thread->set_vframe_array_head(NULL);
aoqi@0 530
aoqi@0 531 // Free the previous UnrollBlock
aoqi@0 532 vframeArray* old_array = thread->vframe_array_last();
aoqi@0 533 thread->set_vframe_array_last(array);
aoqi@0 534
aoqi@0 535 if (old_array != NULL) {
aoqi@0 536 UnrollBlock* old_info = old_array->unroll_block();
aoqi@0 537 old_array->set_unroll_block(NULL);
aoqi@0 538 delete old_info;
aoqi@0 539 delete old_array;
aoqi@0 540 }
aoqi@0 541
aoqi@0 542 // Deallocate any resource creating in this routine and any ResourceObjs allocated
aoqi@0 543 // inside the vframeArray (StackValueCollections)
aoqi@0 544
aoqi@0 545 delete thread->deopt_mark();
aoqi@0 546 thread->set_deopt_mark(NULL);
aoqi@0 547 thread->set_deopt_nmethod(NULL);
aoqi@0 548
aoqi@0 549
aoqi@0 550 if (JvmtiExport::can_pop_frame()) {
aoqi@0 551 #ifndef CC_INTERP
aoqi@0 552 // Regardless of whether we entered this routine with the pending
aoqi@0 553 // popframe condition bit set, we should always clear it now
aoqi@0 554 thread->clear_popframe_condition();
aoqi@0 555 #else
aoqi@0 556 // C++ interpeter will clear has_pending_popframe when it enters
aoqi@0 557 // with method_resume. For deopt_resume2 we clear it now.
aoqi@0 558 if (thread->popframe_forcing_deopt_reexecution())
aoqi@0 559 thread->clear_popframe_condition();
aoqi@0 560 #endif /* CC_INTERP */
aoqi@0 561 }
aoqi@0 562
aoqi@0 563 // unpack_frames() is called at the end of the deoptimization handler
aoqi@0 564 // and (in C2) at the end of the uncommon trap handler. Note this fact
aoqi@0 565 // so that an asynchronous stack walker can work again. This counter is
aoqi@0 566 // incremented at the beginning of fetch_unroll_info() and (in C2) at
aoqi@0 567 // the beginning of uncommon_trap().
aoqi@0 568 thread->dec_in_deopt_handler();
aoqi@0 569 }
aoqi@0 570
aoqi@0 571
aoqi@0 572 // Return BasicType of value being returned
aoqi@0 573 JRT_LEAF(BasicType, Deoptimization::unpack_frames(JavaThread* thread, int exec_mode))
aoqi@0 574
aoqi@0 575 // We are already active int he special DeoptResourceMark any ResourceObj's we
aoqi@0 576 // allocate will be freed at the end of the routine.
aoqi@0 577
aoqi@0 578 // It is actually ok to allocate handles in a leaf method. It causes no safepoints,
aoqi@0 579 // but makes the entry a little slower. There is however a little dance we have to
aoqi@0 580 // do in debug mode to get around the NoHandleMark code in the JRT_LEAF macro
aoqi@0 581 ResetNoHandleMark rnhm; // No-op in release/product versions
aoqi@0 582 HandleMark hm;
aoqi@0 583
aoqi@0 584 frame stub_frame = thread->last_frame();
aoqi@0 585
aoqi@0 586 // Since the frame to unpack is the top frame of this thread, the vframe_array_head
aoqi@0 587 // must point to the vframeArray for the unpack frame.
aoqi@0 588 vframeArray* array = thread->vframe_array_head();
aoqi@0 589
aoqi@0 590 #ifndef PRODUCT
aoqi@0 591 if (TraceDeoptimization) {
aoqi@0 592 ttyLocker ttyl;
aoqi@0 593 tty->print_cr("DEOPT UNPACKING thread " INTPTR_FORMAT " vframeArray " INTPTR_FORMAT " mode %d", thread, array, exec_mode);
aoqi@0 594 }
aoqi@0 595 #endif
aoqi@0 596 Events::log(thread, "DEOPT UNPACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT " mode %d",
aoqi@0 597 stub_frame.pc(), stub_frame.sp(), exec_mode);
aoqi@0 598
aoqi@0 599 UnrollBlock* info = array->unroll_block();
aoqi@0 600
aoqi@0 601 // Unpack the interpreter frames and any adapter frame (c2 only) we might create.
aoqi@0 602 array->unpack_to_stack(stub_frame, exec_mode, info->caller_actual_parameters());
aoqi@0 603
aoqi@0 604 BasicType bt = info->return_type();
aoqi@0 605
aoqi@0 606 // If we have an exception pending, claim that the return type is an oop
aoqi@0 607 // so the deopt_blob does not overwrite the exception_oop.
aoqi@0 608
aoqi@0 609 if (exec_mode == Unpack_exception)
aoqi@0 610 bt = T_OBJECT;
aoqi@0 611
aoqi@0 612 // Cleanup thread deopt data
aoqi@0 613 cleanup_deopt_info(thread, array);
aoqi@0 614
aoqi@0 615 #ifndef PRODUCT
aoqi@0 616 if (VerifyStack) {
aoqi@0 617 ResourceMark res_mark;
aoqi@0 618
aoqi@0 619 thread->validate_frame_layout();
aoqi@0 620
aoqi@0 621 // Verify that the just-unpacked frames match the interpreter's
aoqi@0 622 // notions of expression stack and locals
aoqi@0 623 vframeArray* cur_array = thread->vframe_array_last();
aoqi@0 624 RegisterMap rm(thread, false);
aoqi@0 625 rm.set_include_argument_oops(false);
aoqi@0 626 bool is_top_frame = true;
aoqi@0 627 int callee_size_of_parameters = 0;
aoqi@0 628 int callee_max_locals = 0;
aoqi@0 629 for (int i = 0; i < cur_array->frames(); i++) {
aoqi@0 630 vframeArrayElement* el = cur_array->element(i);
aoqi@0 631 frame* iframe = el->iframe();
aoqi@0 632 guarantee(iframe->is_interpreted_frame(), "Wrong frame type");
aoqi@0 633
aoqi@0 634 // Get the oop map for this bci
aoqi@0 635 InterpreterOopMap mask;
aoqi@0 636 int cur_invoke_parameter_size = 0;
aoqi@0 637 bool try_next_mask = false;
aoqi@0 638 int next_mask_expression_stack_size = -1;
aoqi@0 639 int top_frame_expression_stack_adjustment = 0;
aoqi@0 640 methodHandle mh(thread, iframe->interpreter_frame_method());
aoqi@0 641 OopMapCache::compute_one_oop_map(mh, iframe->interpreter_frame_bci(), &mask);
aoqi@0 642 BytecodeStream str(mh);
aoqi@0 643 str.set_start(iframe->interpreter_frame_bci());
aoqi@0 644 int max_bci = mh->code_size();
aoqi@0 645 // Get to the next bytecode if possible
aoqi@0 646 assert(str.bci() < max_bci, "bci in interpreter frame out of bounds");
aoqi@0 647 // Check to see if we can grab the number of outgoing arguments
aoqi@0 648 // at an uncommon trap for an invoke (where the compiler
aoqi@0 649 // generates debug info before the invoke has executed)
aoqi@0 650 Bytecodes::Code cur_code = str.next();
aoqi@0 651 if (cur_code == Bytecodes::_invokevirtual ||
aoqi@0 652 cur_code == Bytecodes::_invokespecial ||
aoqi@0 653 cur_code == Bytecodes::_invokestatic ||
aoqi@0 654 cur_code == Bytecodes::_invokeinterface ||
aoqi@0 655 cur_code == Bytecodes::_invokedynamic) {
aoqi@0 656 Bytecode_invoke invoke(mh, iframe->interpreter_frame_bci());
aoqi@0 657 Symbol* signature = invoke.signature();
aoqi@0 658 ArgumentSizeComputer asc(signature);
aoqi@0 659 cur_invoke_parameter_size = asc.size();
aoqi@0 660 if (invoke.has_receiver()) {
aoqi@0 661 // Add in receiver
aoqi@0 662 ++cur_invoke_parameter_size;
aoqi@0 663 }
aoqi@0 664 if (i != 0 && !invoke.is_invokedynamic() && MethodHandles::has_member_arg(invoke.klass(), invoke.name())) {
aoqi@0 665 callee_size_of_parameters++;
aoqi@0 666 }
aoqi@0 667 }
aoqi@0 668 if (str.bci() < max_bci) {
aoqi@0 669 Bytecodes::Code bc = str.next();
aoqi@0 670 if (bc >= 0) {
aoqi@0 671 // The interpreter oop map generator reports results before
aoqi@0 672 // the current bytecode has executed except in the case of
aoqi@0 673 // calls. It seems to be hard to tell whether the compiler
aoqi@0 674 // has emitted debug information matching the "state before"
aoqi@0 675 // a given bytecode or the state after, so we try both
aoqi@0 676 switch (cur_code) {
aoqi@0 677 case Bytecodes::_invokevirtual:
aoqi@0 678 case Bytecodes::_invokespecial:
aoqi@0 679 case Bytecodes::_invokestatic:
aoqi@0 680 case Bytecodes::_invokeinterface:
aoqi@0 681 case Bytecodes::_invokedynamic:
aoqi@0 682 case Bytecodes::_athrow:
aoqi@0 683 break;
aoqi@0 684 default: {
aoqi@0 685 InterpreterOopMap next_mask;
aoqi@0 686 OopMapCache::compute_one_oop_map(mh, str.bci(), &next_mask);
aoqi@0 687 next_mask_expression_stack_size = next_mask.expression_stack_size();
aoqi@0 688 // Need to subtract off the size of the result type of
aoqi@0 689 // the bytecode because this is not described in the
aoqi@0 690 // debug info but returned to the interpreter in the TOS
aoqi@0 691 // caching register
aoqi@0 692 BasicType bytecode_result_type = Bytecodes::result_type(cur_code);
aoqi@0 693 if (bytecode_result_type != T_ILLEGAL) {
aoqi@0 694 top_frame_expression_stack_adjustment = type2size[bytecode_result_type];
aoqi@0 695 }
aoqi@0 696 assert(top_frame_expression_stack_adjustment >= 0, "");
aoqi@0 697 try_next_mask = true;
aoqi@0 698 break;
aoqi@0 699 }
aoqi@0 700 }
aoqi@0 701 }
aoqi@0 702 }
aoqi@0 703
aoqi@0 704 // Verify stack depth and oops in frame
aoqi@0 705 // This assertion may be dependent on the platform we're running on and may need modification (tested on x86 and sparc)
aoqi@0 706 if (!(
aoqi@0 707 /* SPARC */
aoqi@0 708 (iframe->interpreter_frame_expression_stack_size() == mask.expression_stack_size() + callee_size_of_parameters) ||
aoqi@0 709 /* x86 */
aoqi@0 710 (iframe->interpreter_frame_expression_stack_size() == mask.expression_stack_size() + callee_max_locals) ||
aoqi@0 711 (try_next_mask &&
aoqi@0 712 (iframe->interpreter_frame_expression_stack_size() == (next_mask_expression_stack_size -
aoqi@0 713 top_frame_expression_stack_adjustment))) ||
aoqi@0 714 (is_top_frame && (exec_mode == Unpack_exception) && iframe->interpreter_frame_expression_stack_size() == 0) ||
aoqi@123 715 (is_top_frame && (exec_mode == Unpack_uncommon_trap || exec_mode == Unpack_reexecute || el->should_reexecute()) &&
aoqi@0 716 (iframe->interpreter_frame_expression_stack_size() == mask.expression_stack_size() + cur_invoke_parameter_size))
aoqi@0 717 )) {
aoqi@0 718 ttyLocker ttyl;
aoqi@0 719
aoqi@0 720 // Print out some information that will help us debug the problem
aoqi@0 721 tty->print_cr("Wrong number of expression stack elements during deoptimization");
aoqi@0 722 tty->print_cr(" Error occurred while verifying frame %d (0..%d, 0 is topmost)", i, cur_array->frames() - 1);
aoqi@0 723 tty->print_cr(" Fabricated interpreter frame had %d expression stack elements",
aoqi@0 724 iframe->interpreter_frame_expression_stack_size());
aoqi@0 725 tty->print_cr(" Interpreter oop map had %d expression stack elements", mask.expression_stack_size());
aoqi@0 726 tty->print_cr(" try_next_mask = %d", try_next_mask);
aoqi@0 727 tty->print_cr(" next_mask_expression_stack_size = %d", next_mask_expression_stack_size);
aoqi@0 728 tty->print_cr(" callee_size_of_parameters = %d", callee_size_of_parameters);
aoqi@0 729 tty->print_cr(" callee_max_locals = %d", callee_max_locals);
aoqi@0 730 tty->print_cr(" top_frame_expression_stack_adjustment = %d", top_frame_expression_stack_adjustment);
aoqi@0 731 tty->print_cr(" exec_mode = %d", exec_mode);
aoqi@0 732 tty->print_cr(" cur_invoke_parameter_size = %d", cur_invoke_parameter_size);
aoqi@0 733 tty->print_cr(" Thread = " INTPTR_FORMAT ", thread ID = " UINTX_FORMAT, thread, thread->osthread()->thread_id());
aoqi@0 734 tty->print_cr(" Interpreted frames:");
aoqi@0 735 for (int k = 0; k < cur_array->frames(); k++) {
aoqi@0 736 vframeArrayElement* el = cur_array->element(k);
aoqi@0 737 tty->print_cr(" %s (bci %d)", el->method()->name_and_sig_as_C_string(), el->bci());
aoqi@0 738 }
aoqi@0 739 cur_array->print_on_2(tty);
aoqi@0 740 guarantee(false, "wrong number of expression stack elements during deopt");
aoqi@0 741 }
aoqi@0 742 VerifyOopClosure verify;
aoqi@0 743 iframe->oops_interpreted_do(&verify, NULL, &rm, false);
aoqi@0 744 callee_size_of_parameters = mh->size_of_parameters();
aoqi@0 745 callee_max_locals = mh->max_locals();
aoqi@0 746 is_top_frame = false;
aoqi@0 747 }
aoqi@0 748 }
aoqi@0 749 #endif /* !PRODUCT */
aoqi@0 750
aoqi@0 751
aoqi@0 752 return bt;
aoqi@0 753 JRT_END
aoqi@0 754
aoqi@0 755
aoqi@0 756 int Deoptimization::deoptimize_dependents() {
aoqi@0 757 Threads::deoptimized_wrt_marked_nmethods();
aoqi@0 758 return 0;
aoqi@0 759 }
aoqi@0 760
aoqi@0 761
aoqi@0 762 #ifdef COMPILER2
aoqi@0 763 bool Deoptimization::realloc_objects(JavaThread* thread, frame* fr, GrowableArray<ScopeValue*>* objects, TRAPS) {
aoqi@0 764 Handle pending_exception(thread->pending_exception());
aoqi@0 765 const char* exception_file = thread->exception_file();
aoqi@0 766 int exception_line = thread->exception_line();
aoqi@0 767 thread->clear_pending_exception();
aoqi@0 768
roland@7419 769 bool failures = false;
roland@7419 770
aoqi@0 771 for (int i = 0; i < objects->length(); i++) {
aoqi@0 772 assert(objects->at(i)->is_object(), "invalid debug information");
aoqi@0 773 ObjectValue* sv = (ObjectValue*) objects->at(i);
aoqi@0 774
aoqi@0 775 KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
aoqi@0 776 oop obj = NULL;
aoqi@0 777
aoqi@0 778 if (k->oop_is_instance()) {
aoqi@0 779 InstanceKlass* ik = InstanceKlass::cast(k());
roland@7419 780 obj = ik->allocate_instance(THREAD);
aoqi@0 781 } else if (k->oop_is_typeArray()) {
aoqi@0 782 TypeArrayKlass* ak = TypeArrayKlass::cast(k());
aoqi@0 783 assert(sv->field_size() % type2size[ak->element_type()] == 0, "non-integral array length");
aoqi@0 784 int len = sv->field_size() / type2size[ak->element_type()];
roland@7419 785 obj = ak->allocate(len, THREAD);
aoqi@0 786 } else if (k->oop_is_objArray()) {
aoqi@0 787 ObjArrayKlass* ak = ObjArrayKlass::cast(k());
roland@7419 788 obj = ak->allocate(sv->field_size(), THREAD);
aoqi@0 789 }
aoqi@0 790
roland@7419 791 if (obj == NULL) {
roland@7419 792 failures = true;
roland@7419 793 }
roland@7419 794
aoqi@0 795 assert(sv->value().is_null(), "redundant reallocation");
roland@7419 796 assert(obj != NULL || HAS_PENDING_EXCEPTION, "allocation should succeed or we should get an exception");
roland@7419 797 CLEAR_PENDING_EXCEPTION;
aoqi@0 798 sv->set_value(obj);
aoqi@0 799 }
aoqi@0 800
roland@7419 801 if (failures) {
roland@7419 802 THROW_OOP_(Universe::out_of_memory_error_realloc_objects(), failures);
roland@7419 803 } else if (pending_exception.not_null()) {
aoqi@0 804 thread->set_pending_exception(pending_exception(), exception_file, exception_line);
aoqi@0 805 }
aoqi@0 806
roland@7419 807 return failures;
aoqi@0 808 }
aoqi@0 809
aoqi@0 810 // This assumes that the fields are stored in ObjectValue in the same order
aoqi@0 811 // they are yielded by do_nonstatic_fields.
aoqi@0 812 class FieldReassigner: public FieldClosure {
aoqi@0 813 frame* _fr;
aoqi@0 814 RegisterMap* _reg_map;
aoqi@0 815 ObjectValue* _sv;
aoqi@0 816 InstanceKlass* _ik;
aoqi@0 817 oop _obj;
aoqi@0 818
aoqi@0 819 int _i;
aoqi@0 820 public:
aoqi@0 821 FieldReassigner(frame* fr, RegisterMap* reg_map, ObjectValue* sv, oop obj) :
aoqi@0 822 _fr(fr), _reg_map(reg_map), _sv(sv), _obj(obj), _i(0) {}
aoqi@0 823
aoqi@0 824 int i() const { return _i; }
aoqi@0 825
aoqi@0 826
aoqi@0 827 void do_field(fieldDescriptor* fd) {
aoqi@0 828 intptr_t val;
aoqi@0 829 StackValue* value =
aoqi@0 830 StackValue::create_stack_value(_fr, _reg_map, _sv->field_at(i()));
aoqi@0 831 int offset = fd->offset();
aoqi@0 832 switch (fd->field_type()) {
aoqi@0 833 case T_OBJECT: case T_ARRAY:
aoqi@0 834 assert(value->type() == T_OBJECT, "Agreement.");
aoqi@0 835 _obj->obj_field_put(offset, value->get_obj()());
aoqi@0 836 break;
aoqi@0 837
aoqi@0 838 case T_LONG: case T_DOUBLE: {
aoqi@0 839 assert(value->type() == T_INT, "Agreement.");
aoqi@0 840 StackValue* low =
aoqi@0 841 StackValue::create_stack_value(_fr, _reg_map, _sv->field_at(++_i));
aoqi@0 842 #ifdef _LP64
aoqi@0 843 jlong res = (jlong)low->get_int();
aoqi@0 844 #else
aoqi@0 845 #ifdef SPARC
aoqi@0 846 // For SPARC we have to swap high and low words.
aoqi@0 847 jlong res = jlong_from((jint)low->get_int(), (jint)value->get_int());
aoqi@0 848 #else
aoqi@0 849 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
aoqi@0 850 #endif //SPARC
aoqi@0 851 #endif
aoqi@0 852 _obj->long_field_put(offset, res);
aoqi@0 853 break;
aoqi@0 854 }
aoqi@0 855 // Have to cast to INT (32 bits) pointer to avoid little/big-endian problem.
aoqi@0 856 case T_INT: case T_FLOAT: // 4 bytes.
aoqi@0 857 assert(value->type() == T_INT, "Agreement.");
aoqi@0 858 val = value->get_int();
aoqi@0 859 _obj->int_field_put(offset, (jint)*((jint*)&val));
aoqi@0 860 break;
aoqi@0 861
kevinw@8395 862 case T_SHORT:
aoqi@0 863 assert(value->type() == T_INT, "Agreement.");
aoqi@0 864 val = value->get_int();
aoqi@0 865 _obj->short_field_put(offset, (jshort)*((jint*)&val));
aoqi@0 866 break;
aoqi@0 867
kevinw@8395 868 case T_CHAR:
kevinw@8395 869 assert(value->type() == T_INT, "Agreement.");
kevinw@8395 870 val = value->get_int();
kevinw@8395 871 _obj->char_field_put(offset, (jchar)*((jint*)&val));
kevinw@8395 872 break;
kevinw@8395 873
kevinw@8395 874 case T_BYTE:
kevinw@8395 875 assert(value->type() == T_INT, "Agreement.");
kevinw@8395 876 val = value->get_int();
kevinw@8395 877 _obj->byte_field_put(offset, (jbyte)*((jint*)&val));
kevinw@8395 878 break;
kevinw@8395 879
kevinw@8395 880 case T_BOOLEAN:
aoqi@0 881 assert(value->type() == T_INT, "Agreement.");
aoqi@0 882 val = value->get_int();
aoqi@0 883 _obj->bool_field_put(offset, (jboolean)*((jint*)&val));
aoqi@0 884 break;
aoqi@0 885
aoqi@0 886 default:
aoqi@0 887 ShouldNotReachHere();
aoqi@0 888 }
aoqi@0 889 _i++;
aoqi@0 890 }
aoqi@0 891 };
aoqi@0 892
aoqi@0 893 // restore elements of an eliminated type array
aoqi@0 894 void Deoptimization::reassign_type_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, typeArrayOop obj, BasicType type) {
aoqi@0 895 int index = 0;
aoqi@0 896 intptr_t val;
aoqi@0 897
aoqi@0 898 for (int i = 0; i < sv->field_size(); i++) {
aoqi@0 899 StackValue* value = StackValue::create_stack_value(fr, reg_map, sv->field_at(i));
aoqi@0 900 switch(type) {
aoqi@0 901 case T_LONG: case T_DOUBLE: {
aoqi@0 902 assert(value->type() == T_INT, "Agreement.");
aoqi@0 903 StackValue* low =
aoqi@0 904 StackValue::create_stack_value(fr, reg_map, sv->field_at(++i));
aoqi@0 905 #ifdef _LP64
aoqi@0 906 jlong res = (jlong)low->get_int();
aoqi@0 907 #else
aoqi@0 908 #ifdef SPARC
aoqi@0 909 // For SPARC we have to swap high and low words.
aoqi@0 910 jlong res = jlong_from((jint)low->get_int(), (jint)value->get_int());
aoqi@0 911 #else
aoqi@0 912 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
aoqi@0 913 #endif //SPARC
aoqi@0 914 #endif
aoqi@0 915 obj->long_at_put(index, res);
aoqi@0 916 break;
aoqi@0 917 }
aoqi@0 918
aoqi@0 919 // Have to cast to INT (32 bits) pointer to avoid little/big-endian problem.
aoqi@0 920 case T_INT: case T_FLOAT: // 4 bytes.
aoqi@0 921 assert(value->type() == T_INT, "Agreement.");
aoqi@0 922 val = value->get_int();
aoqi@0 923 obj->int_at_put(index, (jint)*((jint*)&val));
aoqi@0 924 break;
aoqi@0 925
kevinw@8395 926 case T_SHORT:
aoqi@0 927 assert(value->type() == T_INT, "Agreement.");
aoqi@0 928 val = value->get_int();
aoqi@0 929 obj->short_at_put(index, (jshort)*((jint*)&val));
aoqi@0 930 break;
aoqi@0 931
kevinw@8395 932 case T_CHAR:
kevinw@8395 933 assert(value->type() == T_INT, "Agreement.");
kevinw@8395 934 val = value->get_int();
kevinw@8395 935 obj->char_at_put(index, (jchar)*((jint*)&val));
kevinw@8395 936 break;
kevinw@8395 937
kevinw@8395 938 case T_BYTE:
kevinw@8395 939 assert(value->type() == T_INT, "Agreement.");
kevinw@8395 940 val = value->get_int();
kevinw@8395 941 obj->byte_at_put(index, (jbyte)*((jint*)&val));
kevinw@8395 942 break;
kevinw@8395 943
kevinw@8395 944 case T_BOOLEAN:
aoqi@0 945 assert(value->type() == T_INT, "Agreement.");
aoqi@0 946 val = value->get_int();
aoqi@0 947 obj->bool_at_put(index, (jboolean)*((jint*)&val));
aoqi@0 948 break;
aoqi@0 949
aoqi@0 950 default:
aoqi@0 951 ShouldNotReachHere();
aoqi@0 952 }
aoqi@0 953 index++;
aoqi@0 954 }
aoqi@0 955 }
aoqi@0 956
aoqi@0 957
aoqi@0 958 // restore fields of an eliminated object array
aoqi@0 959 void Deoptimization::reassign_object_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, objArrayOop obj) {
aoqi@0 960 for (int i = 0; i < sv->field_size(); i++) {
aoqi@0 961 StackValue* value = StackValue::create_stack_value(fr, reg_map, sv->field_at(i));
aoqi@0 962 assert(value->type() == T_OBJECT, "object element expected");
aoqi@0 963 obj->obj_at_put(i, value->get_obj()());
aoqi@0 964 }
aoqi@0 965 }
aoqi@0 966
aoqi@0 967
aoqi@0 968 // restore fields of all eliminated objects and arrays
roland@7419 969 void Deoptimization::reassign_fields(frame* fr, RegisterMap* reg_map, GrowableArray<ScopeValue*>* objects, bool realloc_failures) {
aoqi@0 970 for (int i = 0; i < objects->length(); i++) {
aoqi@0 971 ObjectValue* sv = (ObjectValue*) objects->at(i);
aoqi@0 972 KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
aoqi@0 973 Handle obj = sv->value();
roland@7419 974 assert(obj.not_null() || realloc_failures, "reallocation was missed");
roland@7419 975 if (obj.is_null()) {
roland@7419 976 continue;
roland@7419 977 }
aoqi@0 978
aoqi@0 979 if (k->oop_is_instance()) {
aoqi@0 980 InstanceKlass* ik = InstanceKlass::cast(k());
aoqi@0 981 FieldReassigner reassign(fr, reg_map, sv, obj());
aoqi@0 982 ik->do_nonstatic_fields(&reassign);
aoqi@0 983 } else if (k->oop_is_typeArray()) {
aoqi@0 984 TypeArrayKlass* ak = TypeArrayKlass::cast(k());
aoqi@0 985 reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
aoqi@0 986 } else if (k->oop_is_objArray()) {
aoqi@0 987 reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
aoqi@0 988 }
aoqi@0 989 }
aoqi@0 990 }
aoqi@0 991
aoqi@0 992
aoqi@0 993 // relock objects for which synchronization was eliminated
roland@7419 994 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
aoqi@0 995 for (int i = 0; i < monitors->length(); i++) {
aoqi@0 996 MonitorInfo* mon_info = monitors->at(i);
aoqi@0 997 if (mon_info->eliminated()) {
roland@7419 998 assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
roland@7419 999 if (!mon_info->owner_is_scalar_replaced()) {
roland@7419 1000 Handle obj = Handle(mon_info->owner());
roland@7419 1001 markOop mark = obj->mark();
roland@7419 1002 if (UseBiasedLocking && mark->has_bias_pattern()) {
roland@7419 1003 // New allocated objects may have the mark set to anonymously biased.
roland@7419 1004 // Also the deoptimized method may called methods with synchronization
roland@7419 1005 // where the thread-local object is bias locked to the current thread.
roland@7419 1006 assert(mark->is_biased_anonymously() ||
roland@7419 1007 mark->biased_locker() == thread, "should be locked to current thread");
roland@7419 1008 // Reset mark word to unbiased prototype.
roland@7419 1009 markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
roland@7419 1010 obj->set_mark(unbiased_prototype);
roland@7419 1011 }
roland@7419 1012 BasicLock* lock = mon_info->lock();
roland@7419 1013 ObjectSynchronizer::slow_enter(obj, lock, thread);
roland@7419 1014 assert(mon_info->owner()->is_locked(), "object must be locked now");
aoqi@0 1015 }
aoqi@0 1016 }
aoqi@0 1017 }
aoqi@0 1018 }
aoqi@0 1019
aoqi@0 1020
aoqi@0 1021 #ifndef PRODUCT
aoqi@0 1022 // print information about reallocated objects
roland@7419 1023 void Deoptimization::print_objects(GrowableArray<ScopeValue*>* objects, bool realloc_failures) {
aoqi@0 1024 fieldDescriptor fd;
aoqi@0 1025
aoqi@0 1026 for (int i = 0; i < objects->length(); i++) {
aoqi@0 1027 ObjectValue* sv = (ObjectValue*) objects->at(i);
aoqi@0 1028 KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
aoqi@0 1029 Handle obj = sv->value();
aoqi@0 1030
aoqi@0 1031 tty->print(" object <" INTPTR_FORMAT "> of type ", (void *)sv->value()());
aoqi@0 1032 k->print_value();
roland@7419 1033 assert(obj.not_null() || realloc_failures, "reallocation was missed");
roland@7419 1034 if (obj.is_null()) {
roland@7419 1035 tty->print(" allocation failed");
roland@7419 1036 } else {
roland@7419 1037 tty->print(" allocated (%d bytes)", obj->size() * HeapWordSize);
roland@7419 1038 }
aoqi@0 1039 tty->cr();
aoqi@0 1040
roland@7419 1041 if (Verbose && !obj.is_null()) {
aoqi@0 1042 k->oop_print_on(obj(), tty);
aoqi@0 1043 }
aoqi@0 1044 }
aoqi@0 1045 }
aoqi@0 1046 #endif
aoqi@0 1047 #endif // COMPILER2
aoqi@0 1048
roland@7419 1049 vframeArray* Deoptimization::create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk, bool realloc_failures) {
aoqi@0 1050 Events::log(thread, "DEOPT PACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT, fr.pc(), fr.sp());
aoqi@0 1051
aoqi@0 1052 #ifndef PRODUCT
aoqi@0 1053 if (TraceDeoptimization) {
aoqi@0 1054 ttyLocker ttyl;
aoqi@0 1055 tty->print("DEOPT PACKING thread " INTPTR_FORMAT " ", thread);
aoqi@0 1056 fr.print_on(tty);
aoqi@0 1057 tty->print_cr(" Virtual frames (innermost first):");
aoqi@0 1058 for (int index = 0; index < chunk->length(); index++) {
aoqi@0 1059 compiledVFrame* vf = chunk->at(index);
aoqi@0 1060 tty->print(" %2d - ", index);
aoqi@0 1061 vf->print_value();
aoqi@0 1062 int bci = chunk->at(index)->raw_bci();
aoqi@0 1063 const char* code_name;
aoqi@0 1064 if (bci == SynchronizationEntryBCI) {
aoqi@0 1065 code_name = "sync entry";
aoqi@0 1066 } else {
aoqi@0 1067 Bytecodes::Code code = vf->method()->code_at(bci);
aoqi@0 1068 code_name = Bytecodes::name(code);
aoqi@0 1069 }
aoqi@0 1070 tty->print(" - %s", code_name);
aoqi@0 1071 tty->print_cr(" @ bci %d ", bci);
aoqi@0 1072 if (Verbose) {
aoqi@0 1073 vf->print();
aoqi@0 1074 tty->cr();
aoqi@0 1075 }
aoqi@0 1076 }
aoqi@0 1077 }
aoqi@0 1078 #endif
aoqi@0 1079
aoqi@0 1080 // Register map for next frame (used for stack crawl). We capture
aoqi@0 1081 // the state of the deopt'ing frame's caller. Thus if we need to
aoqi@0 1082 // stuff a C2I adapter we can properly fill in the callee-save
aoqi@0 1083 // register locations.
aoqi@0 1084 frame caller = fr.sender(reg_map);
aoqi@0 1085 int frame_size = caller.sp() - fr.sp();
aoqi@0 1086
aoqi@0 1087 frame sender = caller;
aoqi@0 1088
aoqi@0 1089 // Since the Java thread being deoptimized will eventually adjust it's own stack,
aoqi@0 1090 // the vframeArray containing the unpacking information is allocated in the C heap.
aoqi@0 1091 // For Compiler1, the caller of the deoptimized frame is saved for use by unpack_frames().
roland@7419 1092 vframeArray* array = vframeArray::allocate(thread, frame_size, chunk, reg_map, sender, caller, fr, realloc_failures);
aoqi@0 1093
aoqi@0 1094 // Compare the vframeArray to the collected vframes
aoqi@0 1095 assert(array->structural_compare(thread, chunk), "just checking");
aoqi@0 1096
aoqi@0 1097 #ifndef PRODUCT
aoqi@0 1098 if (TraceDeoptimization) {
aoqi@0 1099 ttyLocker ttyl;
aoqi@0 1100 tty->print_cr(" Created vframeArray " INTPTR_FORMAT, array);
aoqi@0 1101 }
aoqi@0 1102 #endif // PRODUCT
aoqi@0 1103
aoqi@0 1104 return array;
aoqi@0 1105 }
aoqi@0 1106
roland@7419 1107 #ifdef COMPILER2
roland@7419 1108 void Deoptimization::pop_frames_failed_reallocs(JavaThread* thread, vframeArray* array) {
roland@7419 1109 // Reallocation of some scalar replaced objects failed. Record
roland@7419 1110 // that we need to pop all the interpreter frames for the
roland@7419 1111 // deoptimized compiled frame.
roland@7419 1112 assert(thread->frames_to_pop_failed_realloc() == 0, "missed frames to pop?");
roland@7419 1113 thread->set_frames_to_pop_failed_realloc(array->frames());
roland@7419 1114 // Unlock all monitors here otherwise the interpreter will see a
roland@7419 1115 // mix of locked and unlocked monitors (because of failed
roland@7419 1116 // reallocations of synchronized objects) and be confused.
roland@7419 1117 for (int i = 0; i < array->frames(); i++) {
roland@7419 1118 MonitorChunk* monitors = array->element(i)->monitors();
roland@7419 1119 if (monitors != NULL) {
roland@7419 1120 for (int j = 0; j < monitors->number_of_monitors(); j++) {
roland@7419 1121 BasicObjectLock* src = monitors->at(j);
roland@7419 1122 if (src->obj() != NULL) {
roland@7419 1123 ObjectSynchronizer::fast_exit(src->obj(), src->lock(), thread);
roland@7419 1124 }
roland@7419 1125 }
roland@7419 1126 array->element(i)->free_monitors(thread);
roland@7419 1127 #ifdef ASSERT
roland@7419 1128 array->element(i)->set_removed_monitors();
roland@7419 1129 #endif
roland@7419 1130 }
roland@7419 1131 }
roland@7419 1132 }
roland@7419 1133 #endif
aoqi@0 1134
aoqi@0 1135 static void collect_monitors(compiledVFrame* cvf, GrowableArray<Handle>* objects_to_revoke) {
aoqi@0 1136 GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
aoqi@0 1137 for (int i = 0; i < monitors->length(); i++) {
aoqi@0 1138 MonitorInfo* mon_info = monitors->at(i);
aoqi@0 1139 if (!mon_info->eliminated() && mon_info->owner() != NULL) {
aoqi@0 1140 objects_to_revoke->append(Handle(mon_info->owner()));
aoqi@0 1141 }
aoqi@0 1142 }
aoqi@0 1143 }
aoqi@0 1144
aoqi@0 1145
aoqi@0 1146 void Deoptimization::revoke_biases_of_monitors(JavaThread* thread, frame fr, RegisterMap* map) {
aoqi@0 1147 if (!UseBiasedLocking) {
aoqi@0 1148 return;
aoqi@0 1149 }
aoqi@0 1150
aoqi@0 1151 GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
aoqi@0 1152
aoqi@0 1153 // Unfortunately we don't have a RegisterMap available in most of
aoqi@0 1154 // the places we want to call this routine so we need to walk the
aoqi@0 1155 // stack again to update the register map.
aoqi@0 1156 if (map == NULL || !map->update_map()) {
aoqi@0 1157 StackFrameStream sfs(thread, true);
aoqi@0 1158 bool found = false;
aoqi@0 1159 while (!found && !sfs.is_done()) {
aoqi@0 1160 frame* cur = sfs.current();
aoqi@0 1161 sfs.next();
aoqi@0 1162 found = cur->id() == fr.id();
aoqi@0 1163 }
aoqi@0 1164 assert(found, "frame to be deoptimized not found on target thread's stack");
aoqi@0 1165 map = sfs.register_map();
aoqi@0 1166 }
aoqi@0 1167
aoqi@0 1168 vframe* vf = vframe::new_vframe(&fr, map, thread);
aoqi@0 1169 compiledVFrame* cvf = compiledVFrame::cast(vf);
aoqi@0 1170 // Revoke monitors' biases in all scopes
aoqi@0 1171 while (!cvf->is_top()) {
aoqi@0 1172 collect_monitors(cvf, objects_to_revoke);
aoqi@0 1173 cvf = compiledVFrame::cast(cvf->sender());
aoqi@0 1174 }
aoqi@0 1175 collect_monitors(cvf, objects_to_revoke);
aoqi@0 1176
aoqi@0 1177 if (SafepointSynchronize::is_at_safepoint()) {
aoqi@0 1178 BiasedLocking::revoke_at_safepoint(objects_to_revoke);
aoqi@0 1179 } else {
aoqi@0 1180 BiasedLocking::revoke(objects_to_revoke);
aoqi@0 1181 }
aoqi@0 1182 }
aoqi@0 1183
aoqi@0 1184
aoqi@0 1185 void Deoptimization::revoke_biases_of_monitors(CodeBlob* cb) {
aoqi@0 1186 if (!UseBiasedLocking) {
aoqi@0 1187 return;
aoqi@0 1188 }
aoqi@0 1189
aoqi@0 1190 assert(SafepointSynchronize::is_at_safepoint(), "must only be called from safepoint");
aoqi@0 1191 GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
aoqi@0 1192 for (JavaThread* jt = Threads::first(); jt != NULL ; jt = jt->next()) {
aoqi@0 1193 if (jt->has_last_Java_frame()) {
aoqi@0 1194 StackFrameStream sfs(jt, true);
aoqi@0 1195 while (!sfs.is_done()) {
aoqi@0 1196 frame* cur = sfs.current();
aoqi@0 1197 if (cb->contains(cur->pc())) {
aoqi@0 1198 vframe* vf = vframe::new_vframe(cur, sfs.register_map(), jt);
aoqi@0 1199 compiledVFrame* cvf = compiledVFrame::cast(vf);
aoqi@0 1200 // Revoke monitors' biases in all scopes
aoqi@0 1201 while (!cvf->is_top()) {
aoqi@0 1202 collect_monitors(cvf, objects_to_revoke);
aoqi@0 1203 cvf = compiledVFrame::cast(cvf->sender());
aoqi@0 1204 }
aoqi@0 1205 collect_monitors(cvf, objects_to_revoke);
aoqi@0 1206 }
aoqi@0 1207 sfs.next();
aoqi@0 1208 }
aoqi@0 1209 }
aoqi@0 1210 }
aoqi@0 1211 BiasedLocking::revoke_at_safepoint(objects_to_revoke);
aoqi@0 1212 }
aoqi@0 1213
aoqi@0 1214
aoqi@0 1215 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr) {
aoqi@0 1216 assert(fr.can_be_deoptimized(), "checking frame type");
aoqi@0 1217
aoqi@0 1218 gather_statistics(Reason_constraint, Action_none, Bytecodes::_illegal);
aoqi@0 1219
aoqi@0 1220 // Patch the nmethod so that when execution returns to it we will
aoqi@0 1221 // deopt the execution state and return to the interpreter.
aoqi@0 1222 fr.deoptimize(thread);
aoqi@0 1223 }
aoqi@0 1224
aoqi@0 1225 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map) {
aoqi@0 1226 // Deoptimize only if the frame comes from compile code.
aoqi@0 1227 // Do not deoptimize the frame which is already patched
aoqi@0 1228 // during the execution of the loops below.
aoqi@0 1229 if (!fr.is_compiled_frame() || fr.is_deoptimized_frame()) {
aoqi@0 1230 return;
aoqi@0 1231 }
aoqi@0 1232 ResourceMark rm;
aoqi@0 1233 DeoptimizationMarker dm;
aoqi@0 1234 if (UseBiasedLocking) {
aoqi@0 1235 revoke_biases_of_monitors(thread, fr, map);
aoqi@0 1236 }
aoqi@0 1237 deoptimize_single_frame(thread, fr);
aoqi@0 1238
aoqi@0 1239 }
aoqi@0 1240
aoqi@0 1241
aoqi@0 1242 void Deoptimization::deoptimize_frame_internal(JavaThread* thread, intptr_t* id) {
aoqi@0 1243 assert(thread == Thread::current() || SafepointSynchronize::is_at_safepoint(),
aoqi@0 1244 "can only deoptimize other thread at a safepoint");
aoqi@0 1245 // Compute frame and register map based on thread and sp.
aoqi@0 1246 RegisterMap reg_map(thread, UseBiasedLocking);
aoqi@0 1247 frame fr = thread->last_frame();
aoqi@0 1248 while (fr.id() != id) {
aoqi@0 1249 fr = fr.sender(&reg_map);
aoqi@0 1250 }
aoqi@0 1251 deoptimize(thread, fr, &reg_map);
aoqi@0 1252 }
aoqi@0 1253
aoqi@0 1254
aoqi@0 1255 void Deoptimization::deoptimize_frame(JavaThread* thread, intptr_t* id) {
aoqi@0 1256 if (thread == Thread::current()) {
aoqi@0 1257 Deoptimization::deoptimize_frame_internal(thread, id);
aoqi@0 1258 } else {
aoqi@0 1259 VM_DeoptimizeFrame deopt(thread, id);
aoqi@0 1260 VMThread::execute(&deopt);
aoqi@0 1261 }
aoqi@0 1262 }
aoqi@0 1263
aoqi@0 1264
aoqi@0 1265 // JVMTI PopFrame support
aoqi@0 1266 JRT_LEAF(void, Deoptimization::popframe_preserve_args(JavaThread* thread, int bytes_to_save, void* start_address))
aoqi@0 1267 {
aoqi@0 1268 thread->popframe_preserve_args(in_ByteSize(bytes_to_save), start_address);
aoqi@0 1269 }
aoqi@0 1270 JRT_END
aoqi@0 1271
aoqi@0 1272
aoqi@0 1273 #if defined(COMPILER2) || defined(SHARK)
aoqi@0 1274 void Deoptimization::load_class_by_index(constantPoolHandle constant_pool, int index, TRAPS) {
aoqi@0 1275 // in case of an unresolved klass entry, load the class.
aoqi@0 1276 if (constant_pool->tag_at(index).is_unresolved_klass()) {
aoqi@0 1277 Klass* tk = constant_pool->klass_at(index, CHECK);
aoqi@0 1278 return;
aoqi@0 1279 }
aoqi@0 1280
aoqi@0 1281 if (!constant_pool->tag_at(index).is_symbol()) return;
aoqi@0 1282
aoqi@0 1283 Handle class_loader (THREAD, constant_pool->pool_holder()->class_loader());
aoqi@0 1284 Symbol* symbol = constant_pool->symbol_at(index);
aoqi@0 1285
aoqi@0 1286 // class name?
aoqi@0 1287 if (symbol->byte_at(0) != '(') {
aoqi@0 1288 Handle protection_domain (THREAD, constant_pool->pool_holder()->protection_domain());
aoqi@0 1289 SystemDictionary::resolve_or_null(symbol, class_loader, protection_domain, CHECK);
aoqi@0 1290 return;
aoqi@0 1291 }
aoqi@0 1292
aoqi@0 1293 // then it must be a signature!
aoqi@0 1294 ResourceMark rm(THREAD);
aoqi@0 1295 for (SignatureStream ss(symbol); !ss.is_done(); ss.next()) {
aoqi@0 1296 if (ss.is_object()) {
aoqi@0 1297 Symbol* class_name = ss.as_symbol(CHECK);
aoqi@0 1298 Handle protection_domain (THREAD, constant_pool->pool_holder()->protection_domain());
aoqi@0 1299 SystemDictionary::resolve_or_null(class_name, class_loader, protection_domain, CHECK);
aoqi@0 1300 }
aoqi@0 1301 }
aoqi@0 1302 }
aoqi@0 1303
aoqi@0 1304
aoqi@0 1305 void Deoptimization::load_class_by_index(constantPoolHandle constant_pool, int index) {
aoqi@0 1306 EXCEPTION_MARK;
aoqi@0 1307 load_class_by_index(constant_pool, index, THREAD);
aoqi@0 1308 if (HAS_PENDING_EXCEPTION) {
aoqi@0 1309 // Exception happened during classloading. We ignore the exception here, since it
aoqi@0 1310 // is going to be rethrown since the current activation is going to be deoptimized and
aoqi@0 1311 // the interpreter will re-execute the bytecode.
aoqi@0 1312 CLEAR_PENDING_EXCEPTION;
aoqi@0 1313 // Class loading called java code which may have caused a stack
aoqi@0 1314 // overflow. If the exception was thrown right before the return
aoqi@0 1315 // to the runtime the stack is no longer guarded. Reguard the
aoqi@0 1316 // stack otherwise if we return to the uncommon trap blob and the
aoqi@0 1317 // stack bang causes a stack overflow we crash.
aoqi@0 1318 assert(THREAD->is_Java_thread(), "only a java thread can be here");
aoqi@0 1319 JavaThread* thread = (JavaThread*)THREAD;
aoqi@0 1320 bool guard_pages_enabled = thread->stack_yellow_zone_enabled();
aoqi@0 1321 if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack();
aoqi@0 1322 assert(guard_pages_enabled, "stack banging in uncommon trap blob may cause crash");
aoqi@0 1323 }
aoqi@0 1324 }
aoqi@0 1325
aoqi@0 1326 JRT_ENTRY(void, Deoptimization::uncommon_trap_inner(JavaThread* thread, jint trap_request)) {
aoqi@0 1327 HandleMark hm;
aoqi@0 1328
aoqi@0 1329 // uncommon_trap() is called at the beginning of the uncommon trap
aoqi@0 1330 // handler. Note this fact before we start generating temporary frames
aoqi@0 1331 // that can confuse an asynchronous stack walker. This counter is
aoqi@0 1332 // decremented at the end of unpack_frames().
aoqi@0 1333 thread->inc_in_deopt_handler();
aoqi@0 1334
aoqi@0 1335 // We need to update the map if we have biased locking.
aoqi@0 1336 RegisterMap reg_map(thread, UseBiasedLocking);
aoqi@0 1337 frame stub_frame = thread->last_frame();
aoqi@0 1338 frame fr = stub_frame.sender(&reg_map);
aoqi@0 1339 // Make sure the calling nmethod is not getting deoptimized and removed
aoqi@0 1340 // before we are done with it.
aoqi@0 1341 nmethodLocker nl(fr.pc());
aoqi@0 1342
aoqi@0 1343 // Log a message
aoqi@0 1344 Events::log(thread, "Uncommon trap: trap_request=" PTR32_FORMAT " fr.pc=" INTPTR_FORMAT,
aoqi@0 1345 trap_request, fr.pc());
aoqi@0 1346
aoqi@0 1347 {
aoqi@0 1348 ResourceMark rm;
aoqi@0 1349
aoqi@0 1350 // Revoke biases of any monitors in the frame to ensure we can migrate them
aoqi@0 1351 revoke_biases_of_monitors(thread, fr, &reg_map);
aoqi@0 1352
aoqi@0 1353 DeoptReason reason = trap_request_reason(trap_request);
aoqi@0 1354 DeoptAction action = trap_request_action(trap_request);
aoqi@0 1355 jint unloaded_class_index = trap_request_index(trap_request); // CP idx or -1
aoqi@0 1356
aoqi@0 1357 vframe* vf = vframe::new_vframe(&fr, &reg_map, thread);
aoqi@0 1358 compiledVFrame* cvf = compiledVFrame::cast(vf);
aoqi@0 1359
aoqi@0 1360 nmethod* nm = cvf->code();
aoqi@0 1361
aoqi@0 1362 ScopeDesc* trap_scope = cvf->scope();
aoqi@0 1363 methodHandle trap_method = trap_scope->method();
aoqi@0 1364 int trap_bci = trap_scope->bci();
aoqi@0 1365 Bytecodes::Code trap_bc = trap_method->java_code_at(trap_bci);
aoqi@0 1366
aoqi@0 1367 // Record this event in the histogram.
aoqi@0 1368 gather_statistics(reason, action, trap_bc);
aoqi@0 1369
aoqi@0 1370 // Ensure that we can record deopt. history:
aoqi@0 1371 // Need MDO to record RTM code generation state.
aoqi@0 1372 bool create_if_missing = ProfileTraps RTM_OPT_ONLY( || UseRTMLocking );
aoqi@0 1373
aoqi@0 1374 MethodData* trap_mdo =
aoqi@0 1375 get_method_data(thread, trap_method, create_if_missing);
aoqi@0 1376
aoqi@0 1377 // Log a message
aoqi@0 1378 Events::log_deopt_message(thread, "Uncommon trap: reason=%s action=%s pc=" INTPTR_FORMAT " method=%s @ %d",
aoqi@0 1379 trap_reason_name(reason), trap_action_name(action), fr.pc(),
aoqi@0 1380 trap_method->name_and_sig_as_C_string(), trap_bci);
aoqi@0 1381
aoqi@0 1382 // Print a bunch of diagnostics, if requested.
aoqi@0 1383 if (TraceDeoptimization || LogCompilation) {
aoqi@0 1384 ResourceMark rm;
aoqi@0 1385 ttyLocker ttyl;
aoqi@0 1386 char buf[100];
aoqi@0 1387 if (xtty != NULL) {
kevinw@9327 1388 xtty->begin_head("uncommon_trap thread='" UINTX_FORMAT "' %s",
aoqi@0 1389 os::current_thread_id(),
aoqi@0 1390 format_trap_request(buf, sizeof(buf), trap_request));
aoqi@0 1391 nm->log_identity(xtty);
aoqi@0 1392 }
aoqi@0 1393 Symbol* class_name = NULL;
aoqi@0 1394 bool unresolved = false;
aoqi@0 1395 if (unloaded_class_index >= 0) {
aoqi@0 1396 constantPoolHandle constants (THREAD, trap_method->constants());
aoqi@0 1397 if (constants->tag_at(unloaded_class_index).is_unresolved_klass()) {
aoqi@0 1398 class_name = constants->klass_name_at(unloaded_class_index);
aoqi@0 1399 unresolved = true;
aoqi@0 1400 if (xtty != NULL)
aoqi@0 1401 xtty->print(" unresolved='1'");
aoqi@0 1402 } else if (constants->tag_at(unloaded_class_index).is_symbol()) {
aoqi@0 1403 class_name = constants->symbol_at(unloaded_class_index);
aoqi@0 1404 }
aoqi@0 1405 if (xtty != NULL)
aoqi@0 1406 xtty->name(class_name);
aoqi@0 1407 }
aoqi@0 1408 if (xtty != NULL && trap_mdo != NULL) {
aoqi@0 1409 // Dump the relevant MDO state.
aoqi@0 1410 // This is the deopt count for the current reason, any previous
aoqi@0 1411 // reasons or recompiles seen at this point.
aoqi@0 1412 int dcnt = trap_mdo->trap_count(reason);
aoqi@0 1413 if (dcnt != 0)
aoqi@0 1414 xtty->print(" count='%d'", dcnt);
aoqi@0 1415 ProfileData* pdata = trap_mdo->bci_to_data(trap_bci);
aoqi@0 1416 int dos = (pdata == NULL)? 0: pdata->trap_state();
aoqi@0 1417 if (dos != 0) {
aoqi@0 1418 xtty->print(" state='%s'", format_trap_state(buf, sizeof(buf), dos));
aoqi@0 1419 if (trap_state_is_recompiled(dos)) {
aoqi@0 1420 int recnt2 = trap_mdo->overflow_recompile_count();
aoqi@0 1421 if (recnt2 != 0)
aoqi@0 1422 xtty->print(" recompiles2='%d'", recnt2);
aoqi@0 1423 }
aoqi@0 1424 }
aoqi@0 1425 }
aoqi@0 1426 if (xtty != NULL) {
aoqi@0 1427 xtty->stamp();
aoqi@0 1428 xtty->end_head();
aoqi@0 1429 }
aoqi@0 1430 if (TraceDeoptimization) { // make noise on the tty
aoqi@0 1431 tty->print("Uncommon trap occurred in");
aoqi@0 1432 nm->method()->print_short_name(tty);
aoqi@0 1433 tty->print(" (@" INTPTR_FORMAT ") thread=" UINTX_FORMAT " reason=%s action=%s unloaded_class_index=%d",
aoqi@0 1434 fr.pc(),
aoqi@0 1435 os::current_thread_id(),
aoqi@0 1436 trap_reason_name(reason),
aoqi@0 1437 trap_action_name(action),
aoqi@0 1438 unloaded_class_index);
aoqi@0 1439 if (class_name != NULL) {
aoqi@0 1440 tty->print(unresolved ? " unresolved class: " : " symbol: ");
aoqi@0 1441 class_name->print_symbol_on(tty);
aoqi@0 1442 }
aoqi@0 1443 tty->cr();
aoqi@0 1444 }
aoqi@0 1445 if (xtty != NULL) {
aoqi@0 1446 // Log the precise location of the trap.
aoqi@0 1447 for (ScopeDesc* sd = trap_scope; ; sd = sd->sender()) {
aoqi@0 1448 xtty->begin_elem("jvms bci='%d'", sd->bci());
aoqi@0 1449 xtty->method(sd->method());
aoqi@0 1450 xtty->end_elem();
aoqi@0 1451 if (sd->is_top()) break;
aoqi@0 1452 }
aoqi@0 1453 xtty->tail("uncommon_trap");
aoqi@0 1454 }
aoqi@0 1455 }
aoqi@0 1456 // (End diagnostic printout.)
aoqi@0 1457
aoqi@0 1458 // Load class if necessary
aoqi@0 1459 if (unloaded_class_index >= 0) {
aoqi@0 1460 constantPoolHandle constants(THREAD, trap_method->constants());
aoqi@0 1461 load_class_by_index(constants, unloaded_class_index);
aoqi@0 1462 }
aoqi@0 1463
aoqi@0 1464 // Flush the nmethod if necessary and desirable.
aoqi@0 1465 //
aoqi@0 1466 // We need to avoid situations where we are re-flushing the nmethod
aoqi@0 1467 // because of a hot deoptimization site. Repeated flushes at the same
aoqi@0 1468 // point need to be detected by the compiler and avoided. If the compiler
aoqi@0 1469 // cannot avoid them (or has a bug and "refuses" to avoid them), this
aoqi@0 1470 // module must take measures to avoid an infinite cycle of recompilation
aoqi@0 1471 // and deoptimization. There are several such measures:
aoqi@0 1472 //
aoqi@0 1473 // 1. If a recompilation is ordered a second time at some site X
aoqi@0 1474 // and for the same reason R, the action is adjusted to 'reinterpret',
aoqi@0 1475 // to give the interpreter time to exercise the method more thoroughly.
aoqi@0 1476 // If this happens, the method's overflow_recompile_count is incremented.
aoqi@0 1477 //
aoqi@0 1478 // 2. If the compiler fails to reduce the deoptimization rate, then
aoqi@0 1479 // the method's overflow_recompile_count will begin to exceed the set
aoqi@0 1480 // limit PerBytecodeRecompilationCutoff. If this happens, the action
aoqi@0 1481 // is adjusted to 'make_not_compilable', and the method is abandoned
aoqi@0 1482 // to the interpreter. This is a performance hit for hot methods,
aoqi@0 1483 // but is better than a disastrous infinite cycle of recompilations.
aoqi@0 1484 // (Actually, only the method containing the site X is abandoned.)
aoqi@0 1485 //
aoqi@0 1486 // 3. In parallel with the previous measures, if the total number of
aoqi@0 1487 // recompilations of a method exceeds the much larger set limit
aoqi@0 1488 // PerMethodRecompilationCutoff, the method is abandoned.
aoqi@0 1489 // This should only happen if the method is very large and has
aoqi@0 1490 // many "lukewarm" deoptimizations. The code which enforces this
aoqi@0 1491 // limit is elsewhere (class nmethod, class Method).
aoqi@0 1492 //
aoqi@0 1493 // Note that the per-BCI 'is_recompiled' bit gives the compiler one chance
aoqi@0 1494 // to recompile at each bytecode independently of the per-BCI cutoff.
aoqi@0 1495 //
aoqi@0 1496 // The decision to update code is up to the compiler, and is encoded
aoqi@0 1497 // in the Action_xxx code. If the compiler requests Action_none
aoqi@0 1498 // no trap state is changed, no compiled code is changed, and the
aoqi@0 1499 // computation suffers along in the interpreter.
aoqi@0 1500 //
aoqi@0 1501 // The other action codes specify various tactics for decompilation
aoqi@0 1502 // and recompilation. Action_maybe_recompile is the loosest, and
aoqi@0 1503 // allows the compiled code to stay around until enough traps are seen,
aoqi@0 1504 // and until the compiler gets around to recompiling the trapping method.
aoqi@0 1505 //
aoqi@0 1506 // The other actions cause immediate removal of the present code.
aoqi@0 1507
vlivanov@7890 1508 // Traps caused by injected profile shouldn't pollute trap counts.
vlivanov@7890 1509 bool injected_profile_trap = trap_method->has_injected_profile() &&
vlivanov@7890 1510 (reason == Reason_intrinsic || reason == Reason_unreached);
vlivanov@7890 1511 bool update_trap_state = !injected_profile_trap;
aoqi@0 1512 bool make_not_entrant = false;
aoqi@0 1513 bool make_not_compilable = false;
aoqi@0 1514 bool reprofile = false;
aoqi@0 1515 switch (action) {
aoqi@0 1516 case Action_none:
aoqi@0 1517 // Keep the old code.
aoqi@0 1518 update_trap_state = false;
aoqi@0 1519 break;
aoqi@0 1520 case Action_maybe_recompile:
aoqi@0 1521 // Do not need to invalidate the present code, but we can
aoqi@0 1522 // initiate another
aoqi@0 1523 // Start compiler without (necessarily) invalidating the nmethod.
aoqi@0 1524 // The system will tolerate the old code, but new code should be
aoqi@0 1525 // generated when possible.
aoqi@0 1526 break;
aoqi@0 1527 case Action_reinterpret:
aoqi@0 1528 // Go back into the interpreter for a while, and then consider
aoqi@0 1529 // recompiling form scratch.
aoqi@0 1530 make_not_entrant = true;
aoqi@0 1531 // Reset invocation counter for outer most method.
aoqi@0 1532 // This will allow the interpreter to exercise the bytecodes
aoqi@0 1533 // for a while before recompiling.
aoqi@0 1534 // By contrast, Action_make_not_entrant is immediate.
aoqi@0 1535 //
aoqi@0 1536 // Note that the compiler will track null_check, null_assert,
aoqi@0 1537 // range_check, and class_check events and log them as if they
aoqi@0 1538 // had been traps taken from compiled code. This will update
aoqi@0 1539 // the MDO trap history so that the next compilation will
aoqi@0 1540 // properly detect hot trap sites.
aoqi@0 1541 reprofile = true;
aoqi@0 1542 break;
aoqi@0 1543 case Action_make_not_entrant:
aoqi@0 1544 // Request immediate recompilation, and get rid of the old code.
aoqi@0 1545 // Make them not entrant, so next time they are called they get
aoqi@0 1546 // recompiled. Unloaded classes are loaded now so recompile before next
aoqi@0 1547 // time they are called. Same for uninitialized. The interpreter will
aoqi@0 1548 // link the missing class, if any.
aoqi@0 1549 make_not_entrant = true;
aoqi@0 1550 break;
aoqi@0 1551 case Action_make_not_compilable:
aoqi@0 1552 // Give up on compiling this method at all.
aoqi@0 1553 make_not_entrant = true;
aoqi@0 1554 make_not_compilable = true;
aoqi@0 1555 break;
aoqi@0 1556 default:
aoqi@0 1557 ShouldNotReachHere();
aoqi@0 1558 }
aoqi@0 1559
aoqi@0 1560 // Setting +ProfileTraps fixes the following, on all platforms:
aoqi@0 1561 // 4852688: ProfileInterpreter is off by default for ia64. The result is
aoqi@0 1562 // infinite heroic-opt-uncommon-trap/deopt/recompile cycles, since the
aoqi@0 1563 // recompile relies on a MethodData* to record heroic opt failures.
aoqi@0 1564
aoqi@0 1565 // Whether the interpreter is producing MDO data or not, we also need
aoqi@0 1566 // to use the MDO to detect hot deoptimization points and control
aoqi@0 1567 // aggressive optimization.
aoqi@0 1568 bool inc_recompile_count = false;
aoqi@0 1569 ProfileData* pdata = NULL;
aoqi@0 1570 if (ProfileTraps && update_trap_state && trap_mdo != NULL) {
aoqi@0 1571 assert(trap_mdo == get_method_data(thread, trap_method, false), "sanity");
aoqi@0 1572 uint this_trap_count = 0;
aoqi@0 1573 bool maybe_prior_trap = false;
aoqi@0 1574 bool maybe_prior_recompile = false;
aoqi@0 1575 pdata = query_update_method_data(trap_mdo, trap_bci, reason,
aoqi@0 1576 nm->method(),
aoqi@0 1577 //outputs:
aoqi@0 1578 this_trap_count,
aoqi@0 1579 maybe_prior_trap,
aoqi@0 1580 maybe_prior_recompile);
aoqi@0 1581 // Because the interpreter also counts null, div0, range, and class
aoqi@0 1582 // checks, these traps from compiled code are double-counted.
aoqi@0 1583 // This is harmless; it just means that the PerXTrapLimit values
aoqi@0 1584 // are in effect a little smaller than they look.
aoqi@0 1585
aoqi@0 1586 DeoptReason per_bc_reason = reason_recorded_per_bytecode_if_any(reason);
aoqi@0 1587 if (per_bc_reason != Reason_none) {
aoqi@0 1588 // Now take action based on the partially known per-BCI history.
aoqi@0 1589 if (maybe_prior_trap
aoqi@0 1590 && this_trap_count >= (uint)PerBytecodeTrapLimit) {
aoqi@0 1591 // If there are too many traps at this BCI, force a recompile.
aoqi@0 1592 // This will allow the compiler to see the limit overflow, and
aoqi@0 1593 // take corrective action, if possible. The compiler generally
aoqi@0 1594 // does not use the exact PerBytecodeTrapLimit value, but instead
aoqi@0 1595 // changes its tactics if it sees any traps at all. This provides
aoqi@0 1596 // a little hysteresis, delaying a recompile until a trap happens
aoqi@0 1597 // several times.
aoqi@0 1598 //
aoqi@0 1599 // Actually, since there is only one bit of counter per BCI,
aoqi@0 1600 // the possible per-BCI counts are {0,1,(per-method count)}.
aoqi@0 1601 // This produces accurate results if in fact there is only
aoqi@0 1602 // one hot trap site, but begins to get fuzzy if there are
aoqi@0 1603 // many sites. For example, if there are ten sites each
aoqi@0 1604 // trapping two or more times, they each get the blame for
aoqi@0 1605 // all of their traps.
aoqi@0 1606 make_not_entrant = true;
aoqi@0 1607 }
aoqi@0 1608
aoqi@0 1609 // Detect repeated recompilation at the same BCI, and enforce a limit.
aoqi@0 1610 if (make_not_entrant && maybe_prior_recompile) {
aoqi@0 1611 // More than one recompile at this point.
aoqi@0 1612 inc_recompile_count = maybe_prior_trap;
aoqi@0 1613 }
aoqi@0 1614 } else {
aoqi@0 1615 // For reasons which are not recorded per-bytecode, we simply
aoqi@0 1616 // force recompiles unconditionally.
aoqi@0 1617 // (Note that PerMethodRecompilationCutoff is enforced elsewhere.)
aoqi@0 1618 make_not_entrant = true;
aoqi@0 1619 }
aoqi@0 1620
aoqi@0 1621 // Go back to the compiler if there are too many traps in this method.
aoqi@0 1622 if (this_trap_count >= per_method_trap_limit(reason)) {
aoqi@0 1623 // If there are too many traps in this method, force a recompile.
aoqi@0 1624 // This will allow the compiler to see the limit overflow, and
aoqi@0 1625 // take corrective action, if possible.
aoqi@0 1626 // (This condition is an unlikely backstop only, because the
aoqi@0 1627 // PerBytecodeTrapLimit is more likely to take effect first,
aoqi@0 1628 // if it is applicable.)
aoqi@0 1629 make_not_entrant = true;
aoqi@0 1630 }
aoqi@0 1631
aoqi@0 1632 // Here's more hysteresis: If there has been a recompile at
aoqi@0 1633 // this trap point already, run the method in the interpreter
aoqi@0 1634 // for a while to exercise it more thoroughly.
aoqi@0 1635 if (make_not_entrant && maybe_prior_recompile && maybe_prior_trap) {
aoqi@0 1636 reprofile = true;
aoqi@0 1637 }
aoqi@0 1638
aoqi@0 1639 }
aoqi@0 1640
aoqi@0 1641 // Take requested actions on the method:
aoqi@0 1642
aoqi@0 1643 // Recompile
aoqi@0 1644 if (make_not_entrant) {
aoqi@0 1645 if (!nm->make_not_entrant()) {
aoqi@0 1646 return; // the call did not change nmethod's state
aoqi@0 1647 }
aoqi@0 1648
aoqi@0 1649 if (pdata != NULL) {
aoqi@0 1650 // Record the recompilation event, if any.
aoqi@0 1651 int tstate0 = pdata->trap_state();
aoqi@0 1652 int tstate1 = trap_state_set_recompiled(tstate0, true);
aoqi@0 1653 if (tstate1 != tstate0)
aoqi@0 1654 pdata->set_trap_state(tstate1);
aoqi@0 1655 }
aoqi@0 1656
aoqi@0 1657 #if INCLUDE_RTM_OPT
aoqi@0 1658 // Restart collecting RTM locking abort statistic if the method
aoqi@0 1659 // is recompiled for a reason other than RTM state change.
aoqi@0 1660 // Assume that in new recompiled code the statistic could be different,
aoqi@0 1661 // for example, due to different inlining.
aoqi@0 1662 if ((reason != Reason_rtm_state_change) && (trap_mdo != NULL) &&
aoqi@0 1663 UseRTMDeopt && (nm->rtm_state() != ProfileRTM)) {
aoqi@0 1664 trap_mdo->atomic_set_rtm_state(ProfileRTM);
aoqi@0 1665 }
aoqi@0 1666 #endif
aoqi@0 1667 }
aoqi@0 1668
aoqi@0 1669 if (inc_recompile_count) {
aoqi@0 1670 trap_mdo->inc_overflow_recompile_count();
aoqi@0 1671 if ((uint)trap_mdo->overflow_recompile_count() >
aoqi@0 1672 (uint)PerBytecodeRecompilationCutoff) {
aoqi@0 1673 // Give up on the method containing the bad BCI.
aoqi@0 1674 if (trap_method() == nm->method()) {
aoqi@0 1675 make_not_compilable = true;
aoqi@0 1676 } else {
aoqi@0 1677 trap_method->set_not_compilable(CompLevel_full_optimization, true, "overflow_recompile_count > PerBytecodeRecompilationCutoff");
aoqi@0 1678 // But give grace to the enclosing nm->method().
aoqi@0 1679 }
aoqi@0 1680 }
aoqi@0 1681 }
aoqi@0 1682
aoqi@0 1683 // Reprofile
aoqi@0 1684 if (reprofile) {
aoqi@0 1685 CompilationPolicy::policy()->reprofile(trap_scope, nm->is_osr_method());
aoqi@0 1686 }
aoqi@0 1687
aoqi@0 1688 // Give up compiling
aoqi@0 1689 if (make_not_compilable && !nm->method()->is_not_compilable(CompLevel_full_optimization)) {
aoqi@0 1690 assert(make_not_entrant, "consistent");
aoqi@0 1691 nm->method()->set_not_compilable(CompLevel_full_optimization);
aoqi@0 1692 }
aoqi@0 1693
aoqi@0 1694 } // Free marked resources
aoqi@0 1695
aoqi@0 1696 }
aoqi@0 1697 JRT_END
aoqi@0 1698
aoqi@0 1699 MethodData*
aoqi@0 1700 Deoptimization::get_method_data(JavaThread* thread, methodHandle m,
aoqi@0 1701 bool create_if_missing) {
aoqi@0 1702 Thread* THREAD = thread;
aoqi@0 1703 MethodData* mdo = m()->method_data();
aoqi@0 1704 if (mdo == NULL && create_if_missing && !HAS_PENDING_EXCEPTION) {
aoqi@0 1705 // Build an MDO. Ignore errors like OutOfMemory;
aoqi@0 1706 // that simply means we won't have an MDO to update.
aoqi@0 1707 Method::build_interpreter_method_data(m, THREAD);
aoqi@0 1708 if (HAS_PENDING_EXCEPTION) {
aoqi@0 1709 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
aoqi@0 1710 CLEAR_PENDING_EXCEPTION;
aoqi@0 1711 }
aoqi@0 1712 mdo = m()->method_data();
aoqi@0 1713 }
aoqi@0 1714 return mdo;
aoqi@0 1715 }
aoqi@0 1716
aoqi@0 1717 ProfileData*
aoqi@0 1718 Deoptimization::query_update_method_data(MethodData* trap_mdo,
aoqi@0 1719 int trap_bci,
aoqi@0 1720 Deoptimization::DeoptReason reason,
aoqi@0 1721 Method* compiled_method,
aoqi@0 1722 //outputs:
aoqi@0 1723 uint& ret_this_trap_count,
aoqi@0 1724 bool& ret_maybe_prior_trap,
aoqi@0 1725 bool& ret_maybe_prior_recompile) {
aoqi@0 1726 uint prior_trap_count = trap_mdo->trap_count(reason);
aoqi@0 1727 uint this_trap_count = trap_mdo->inc_trap_count(reason);
aoqi@0 1728
aoqi@0 1729 // If the runtime cannot find a place to store trap history,
aoqi@0 1730 // it is estimated based on the general condition of the method.
aoqi@0 1731 // If the method has ever been recompiled, or has ever incurred
aoqi@0 1732 // a trap with the present reason , then this BCI is assumed
aoqi@0 1733 // (pessimistically) to be the culprit.
aoqi@0 1734 bool maybe_prior_trap = (prior_trap_count != 0);
aoqi@0 1735 bool maybe_prior_recompile = (trap_mdo->decompile_count() != 0);
aoqi@0 1736 ProfileData* pdata = NULL;
aoqi@0 1737
aoqi@0 1738
aoqi@0 1739 // For reasons which are recorded per bytecode, we check per-BCI data.
aoqi@0 1740 DeoptReason per_bc_reason = reason_recorded_per_bytecode_if_any(reason);
aoqi@0 1741 if (per_bc_reason != Reason_none) {
aoqi@0 1742 // Find the profile data for this BCI. If there isn't one,
aoqi@0 1743 // try to allocate one from the MDO's set of spares.
aoqi@0 1744 // This will let us detect a repeated trap at this point.
aoqi@0 1745 pdata = trap_mdo->allocate_bci_to_data(trap_bci, reason_is_speculate(reason) ? compiled_method : NULL);
aoqi@0 1746
aoqi@0 1747 if (pdata != NULL) {
aoqi@0 1748 if (reason_is_speculate(reason) && !pdata->is_SpeculativeTrapData()) {
aoqi@0 1749 if (LogCompilation && xtty != NULL) {
aoqi@0 1750 ttyLocker ttyl;
aoqi@0 1751 // no more room for speculative traps in this MDO
aoqi@0 1752 xtty->elem("speculative_traps_oom");
aoqi@0 1753 }
aoqi@0 1754 }
aoqi@0 1755 // Query the trap state of this profile datum.
aoqi@0 1756 int tstate0 = pdata->trap_state();
aoqi@0 1757 if (!trap_state_has_reason(tstate0, per_bc_reason))
aoqi@0 1758 maybe_prior_trap = false;
aoqi@0 1759 if (!trap_state_is_recompiled(tstate0))
aoqi@0 1760 maybe_prior_recompile = false;
aoqi@0 1761
aoqi@0 1762 // Update the trap state of this profile datum.
aoqi@0 1763 int tstate1 = tstate0;
aoqi@0 1764 // Record the reason.
aoqi@0 1765 tstate1 = trap_state_add_reason(tstate1, per_bc_reason);
aoqi@0 1766 // Store the updated state on the MDO, for next time.
aoqi@0 1767 if (tstate1 != tstate0)
aoqi@0 1768 pdata->set_trap_state(tstate1);
aoqi@0 1769 } else {
aoqi@0 1770 if (LogCompilation && xtty != NULL) {
aoqi@0 1771 ttyLocker ttyl;
aoqi@0 1772 // Missing MDP? Leave a small complaint in the log.
aoqi@0 1773 xtty->elem("missing_mdp bci='%d'", trap_bci);
aoqi@0 1774 }
aoqi@0 1775 }
aoqi@0 1776 }
aoqi@0 1777
aoqi@0 1778 // Return results:
aoqi@0 1779 ret_this_trap_count = this_trap_count;
aoqi@0 1780 ret_maybe_prior_trap = maybe_prior_trap;
aoqi@0 1781 ret_maybe_prior_recompile = maybe_prior_recompile;
aoqi@0 1782 return pdata;
aoqi@0 1783 }
aoqi@0 1784
aoqi@0 1785 void
aoqi@0 1786 Deoptimization::update_method_data_from_interpreter(MethodData* trap_mdo, int trap_bci, int reason) {
aoqi@0 1787 ResourceMark rm;
aoqi@0 1788 // Ignored outputs:
aoqi@0 1789 uint ignore_this_trap_count;
aoqi@0 1790 bool ignore_maybe_prior_trap;
aoqi@0 1791 bool ignore_maybe_prior_recompile;
aoqi@0 1792 assert(!reason_is_speculate(reason), "reason speculate only used by compiler");
aoqi@0 1793 query_update_method_data(trap_mdo, trap_bci,
aoqi@0 1794 (DeoptReason)reason,
aoqi@0 1795 NULL,
aoqi@0 1796 ignore_this_trap_count,
aoqi@0 1797 ignore_maybe_prior_trap,
aoqi@0 1798 ignore_maybe_prior_recompile);
aoqi@0 1799 }
aoqi@0 1800
aoqi@0 1801 Deoptimization::UnrollBlock* Deoptimization::uncommon_trap(JavaThread* thread, jint trap_request) {
aoqi@0 1802
aoqi@0 1803 // Still in Java no safepoints
aoqi@0 1804 {
aoqi@0 1805 // This enters VM and may safepoint
aoqi@0 1806 uncommon_trap_inner(thread, trap_request);
aoqi@0 1807 }
aoqi@0 1808 return fetch_unroll_info_helper(thread);
aoqi@0 1809 }
aoqi@0 1810
aoqi@0 1811 // Local derived constants.
aoqi@0 1812 // Further breakdown of DataLayout::trap_state, as promised by DataLayout.
aoqi@0 1813 const int DS_REASON_MASK = DataLayout::trap_mask >> 1;
aoqi@0 1814 const int DS_RECOMPILE_BIT = DataLayout::trap_mask - DS_REASON_MASK;
aoqi@0 1815
aoqi@0 1816 //---------------------------trap_state_reason---------------------------------
aoqi@0 1817 Deoptimization::DeoptReason
aoqi@0 1818 Deoptimization::trap_state_reason(int trap_state) {
aoqi@0 1819 // This assert provides the link between the width of DataLayout::trap_bits
aoqi@0 1820 // and the encoding of "recorded" reasons. It ensures there are enough
aoqi@0 1821 // bits to store all needed reasons in the per-BCI MDO profile.
aoqi@0 1822 assert(DS_REASON_MASK >= Reason_RECORDED_LIMIT, "enough bits");
aoqi@0 1823 int recompile_bit = (trap_state & DS_RECOMPILE_BIT);
aoqi@0 1824 trap_state -= recompile_bit;
aoqi@0 1825 if (trap_state == DS_REASON_MASK) {
aoqi@0 1826 return Reason_many;
aoqi@0 1827 } else {
aoqi@0 1828 assert((int)Reason_none == 0, "state=0 => Reason_none");
aoqi@0 1829 return (DeoptReason)trap_state;
aoqi@0 1830 }
aoqi@0 1831 }
aoqi@0 1832 //-------------------------trap_state_has_reason-------------------------------
aoqi@0 1833 int Deoptimization::trap_state_has_reason(int trap_state, int reason) {
aoqi@0 1834 assert(reason_is_recorded_per_bytecode((DeoptReason)reason), "valid reason");
aoqi@0 1835 assert(DS_REASON_MASK >= Reason_RECORDED_LIMIT, "enough bits");
aoqi@0 1836 int recompile_bit = (trap_state & DS_RECOMPILE_BIT);
aoqi@0 1837 trap_state -= recompile_bit;
aoqi@0 1838 if (trap_state == DS_REASON_MASK) {
aoqi@0 1839 return -1; // true, unspecifically (bottom of state lattice)
aoqi@0 1840 } else if (trap_state == reason) {
aoqi@0 1841 return 1; // true, definitely
aoqi@0 1842 } else if (trap_state == 0) {
aoqi@0 1843 return 0; // false, definitely (top of state lattice)
aoqi@0 1844 } else {
aoqi@0 1845 return 0; // false, definitely
aoqi@0 1846 }
aoqi@0 1847 }
aoqi@0 1848 //-------------------------trap_state_add_reason-------------------------------
aoqi@0 1849 int Deoptimization::trap_state_add_reason(int trap_state, int reason) {
aoqi@0 1850 assert(reason_is_recorded_per_bytecode((DeoptReason)reason) || reason == Reason_many, "valid reason");
aoqi@0 1851 int recompile_bit = (trap_state & DS_RECOMPILE_BIT);
aoqi@0 1852 trap_state -= recompile_bit;
aoqi@0 1853 if (trap_state == DS_REASON_MASK) {
aoqi@0 1854 return trap_state + recompile_bit; // already at state lattice bottom
aoqi@0 1855 } else if (trap_state == reason) {
aoqi@0 1856 return trap_state + recompile_bit; // the condition is already true
aoqi@0 1857 } else if (trap_state == 0) {
aoqi@0 1858 return reason + recompile_bit; // no condition has yet been true
aoqi@0 1859 } else {
aoqi@0 1860 return DS_REASON_MASK + recompile_bit; // fall to state lattice bottom
aoqi@0 1861 }
aoqi@0 1862 }
aoqi@0 1863 //-----------------------trap_state_is_recompiled------------------------------
aoqi@0 1864 bool Deoptimization::trap_state_is_recompiled(int trap_state) {
aoqi@0 1865 return (trap_state & DS_RECOMPILE_BIT) != 0;
aoqi@0 1866 }
aoqi@0 1867 //-----------------------trap_state_set_recompiled-----------------------------
aoqi@0 1868 int Deoptimization::trap_state_set_recompiled(int trap_state, bool z) {
aoqi@0 1869 if (z) return trap_state | DS_RECOMPILE_BIT;
aoqi@0 1870 else return trap_state & ~DS_RECOMPILE_BIT;
aoqi@0 1871 }
aoqi@0 1872 //---------------------------format_trap_state---------------------------------
aoqi@0 1873 // This is used for debugging and diagnostics, including LogFile output.
aoqi@0 1874 const char* Deoptimization::format_trap_state(char* buf, size_t buflen,
aoqi@0 1875 int trap_state) {
aoqi@0 1876 DeoptReason reason = trap_state_reason(trap_state);
aoqi@0 1877 bool recomp_flag = trap_state_is_recompiled(trap_state);
aoqi@0 1878 // Re-encode the state from its decoded components.
aoqi@0 1879 int decoded_state = 0;
aoqi@0 1880 if (reason_is_recorded_per_bytecode(reason) || reason == Reason_many)
aoqi@0 1881 decoded_state = trap_state_add_reason(decoded_state, reason);
aoqi@0 1882 if (recomp_flag)
aoqi@0 1883 decoded_state = trap_state_set_recompiled(decoded_state, recomp_flag);
aoqi@0 1884 // If the state re-encodes properly, format it symbolically.
aoqi@0 1885 // Because this routine is used for debugging and diagnostics,
aoqi@0 1886 // be robust even if the state is a strange value.
aoqi@0 1887 size_t len;
aoqi@0 1888 if (decoded_state != trap_state) {
aoqi@0 1889 // Random buggy state that doesn't decode??
aoqi@0 1890 len = jio_snprintf(buf, buflen, "#%d", trap_state);
aoqi@0 1891 } else {
aoqi@0 1892 len = jio_snprintf(buf, buflen, "%s%s",
aoqi@0 1893 trap_reason_name(reason),
aoqi@0 1894 recomp_flag ? " recompiled" : "");
aoqi@0 1895 }
aoqi@0 1896 return buf;
aoqi@0 1897 }
aoqi@0 1898
aoqi@0 1899
aoqi@0 1900 //--------------------------------statics--------------------------------------
aoqi@0 1901 Deoptimization::DeoptAction Deoptimization::_unloaded_action
aoqi@0 1902 = Deoptimization::Action_reinterpret;
aoqi@0 1903 const char* Deoptimization::_trap_reason_name[Reason_LIMIT] = {
aoqi@0 1904 // Note: Keep this in sync. with enum DeoptReason.
aoqi@0 1905 "none",
aoqi@0 1906 "null_check",
aoqi@0 1907 "null_assert",
aoqi@0 1908 "range_check",
aoqi@0 1909 "class_check",
aoqi@0 1910 "array_check",
aoqi@0 1911 "intrinsic",
aoqi@0 1912 "bimorphic",
aoqi@0 1913 "unloaded",
aoqi@0 1914 "uninitialized",
aoqi@0 1915 "unreached",
aoqi@0 1916 "unhandled",
aoqi@0 1917 "constraint",
aoqi@0 1918 "div0_check",
aoqi@0 1919 "age",
aoqi@0 1920 "predicate",
aoqi@0 1921 "loop_limit_check",
aoqi@0 1922 "speculate_class_check",
rbackman@7153 1923 "rtm_state_change",
rbackman@7153 1924 "unstable_if"
aoqi@0 1925 };
aoqi@0 1926 const char* Deoptimization::_trap_action_name[Action_LIMIT] = {
aoqi@0 1927 // Note: Keep this in sync. with enum DeoptAction.
aoqi@0 1928 "none",
aoqi@0 1929 "maybe_recompile",
aoqi@0 1930 "reinterpret",
aoqi@0 1931 "make_not_entrant",
aoqi@0 1932 "make_not_compilable"
aoqi@0 1933 };
aoqi@0 1934
aoqi@0 1935 const char* Deoptimization::trap_reason_name(int reason) {
aoqi@0 1936 if (reason == Reason_many) return "many";
aoqi@0 1937 if ((uint)reason < Reason_LIMIT)
aoqi@0 1938 return _trap_reason_name[reason];
aoqi@0 1939 static char buf[20];
aoqi@0 1940 sprintf(buf, "reason%d", reason);
aoqi@0 1941 return buf;
aoqi@0 1942 }
aoqi@0 1943 const char* Deoptimization::trap_action_name(int action) {
aoqi@0 1944 if ((uint)action < Action_LIMIT)
aoqi@0 1945 return _trap_action_name[action];
aoqi@0 1946 static char buf[20];
aoqi@0 1947 sprintf(buf, "action%d", action);
aoqi@0 1948 return buf;
aoqi@0 1949 }
aoqi@0 1950
aoqi@0 1951 // This is used for debugging and diagnostics, including LogFile output.
aoqi@0 1952 const char* Deoptimization::format_trap_request(char* buf, size_t buflen,
aoqi@0 1953 int trap_request) {
aoqi@0 1954 jint unloaded_class_index = trap_request_index(trap_request);
aoqi@0 1955 const char* reason = trap_reason_name(trap_request_reason(trap_request));
aoqi@0 1956 const char* action = trap_action_name(trap_request_action(trap_request));
aoqi@0 1957 size_t len;
aoqi@0 1958 if (unloaded_class_index < 0) {
aoqi@0 1959 len = jio_snprintf(buf, buflen, "reason='%s' action='%s'",
aoqi@0 1960 reason, action);
aoqi@0 1961 } else {
aoqi@0 1962 len = jio_snprintf(buf, buflen, "reason='%s' action='%s' index='%d'",
aoqi@0 1963 reason, action, unloaded_class_index);
aoqi@0 1964 }
aoqi@0 1965 return buf;
aoqi@0 1966 }
aoqi@0 1967
aoqi@0 1968 juint Deoptimization::_deoptimization_hist
aoqi@0 1969 [Deoptimization::Reason_LIMIT]
aoqi@0 1970 [1 + Deoptimization::Action_LIMIT]
aoqi@0 1971 [Deoptimization::BC_CASE_LIMIT]
aoqi@0 1972 = {0};
aoqi@0 1973
aoqi@0 1974 enum {
aoqi@0 1975 LSB_BITS = 8,
aoqi@0 1976 LSB_MASK = right_n_bits(LSB_BITS)
aoqi@0 1977 };
aoqi@0 1978
aoqi@0 1979 void Deoptimization::gather_statistics(DeoptReason reason, DeoptAction action,
aoqi@0 1980 Bytecodes::Code bc) {
aoqi@0 1981 assert(reason >= 0 && reason < Reason_LIMIT, "oob");
aoqi@0 1982 assert(action >= 0 && action < Action_LIMIT, "oob");
aoqi@0 1983 _deoptimization_hist[Reason_none][0][0] += 1; // total
aoqi@0 1984 _deoptimization_hist[reason][0][0] += 1; // per-reason total
aoqi@0 1985 juint* cases = _deoptimization_hist[reason][1+action];
aoqi@0 1986 juint* bc_counter_addr = NULL;
aoqi@0 1987 juint bc_counter = 0;
aoqi@0 1988 // Look for an unused counter, or an exact match to this BC.
aoqi@0 1989 if (bc != Bytecodes::_illegal) {
aoqi@0 1990 for (int bc_case = 0; bc_case < BC_CASE_LIMIT; bc_case++) {
aoqi@0 1991 juint* counter_addr = &cases[bc_case];
aoqi@0 1992 juint counter = *counter_addr;
aoqi@0 1993 if ((counter == 0 && bc_counter_addr == NULL)
aoqi@0 1994 || (Bytecodes::Code)(counter & LSB_MASK) == bc) {
aoqi@0 1995 // this counter is either free or is already devoted to this BC
aoqi@0 1996 bc_counter_addr = counter_addr;
aoqi@0 1997 bc_counter = counter | bc;
aoqi@0 1998 }
aoqi@0 1999 }
aoqi@0 2000 }
aoqi@0 2001 if (bc_counter_addr == NULL) {
aoqi@0 2002 // Overflow, or no given bytecode.
aoqi@0 2003 bc_counter_addr = &cases[BC_CASE_LIMIT-1];
aoqi@0 2004 bc_counter = (*bc_counter_addr & ~LSB_MASK); // clear LSB
aoqi@0 2005 }
aoqi@0 2006 *bc_counter_addr = bc_counter + (1 << LSB_BITS);
aoqi@0 2007 }
aoqi@0 2008
aoqi@0 2009 jint Deoptimization::total_deoptimization_count() {
aoqi@0 2010 return _deoptimization_hist[Reason_none][0][0];
aoqi@0 2011 }
aoqi@0 2012
aoqi@0 2013 jint Deoptimization::deoptimization_count(DeoptReason reason) {
aoqi@0 2014 assert(reason >= 0 && reason < Reason_LIMIT, "oob");
aoqi@0 2015 return _deoptimization_hist[reason][0][0];
aoqi@0 2016 }
aoqi@0 2017
aoqi@0 2018 void Deoptimization::print_statistics() {
aoqi@0 2019 juint total = total_deoptimization_count();
aoqi@0 2020 juint account = total;
aoqi@0 2021 if (total != 0) {
aoqi@0 2022 ttyLocker ttyl;
aoqi@0 2023 if (xtty != NULL) xtty->head("statistics type='deoptimization'");
aoqi@0 2024 tty->print_cr("Deoptimization traps recorded:");
aoqi@0 2025 #define PRINT_STAT_LINE(name, r) \
aoqi@0 2026 tty->print_cr(" %4d (%4.1f%%) %s", (int)(r), ((r) * 100.0) / total, name);
aoqi@0 2027 PRINT_STAT_LINE("total", total);
aoqi@0 2028 // For each non-zero entry in the histogram, print the reason,
aoqi@0 2029 // the action, and (if specifically known) the type of bytecode.
aoqi@0 2030 for (int reason = 0; reason < Reason_LIMIT; reason++) {
aoqi@0 2031 for (int action = 0; action < Action_LIMIT; action++) {
aoqi@0 2032 juint* cases = _deoptimization_hist[reason][1+action];
aoqi@0 2033 for (int bc_case = 0; bc_case < BC_CASE_LIMIT; bc_case++) {
aoqi@0 2034 juint counter = cases[bc_case];
aoqi@0 2035 if (counter != 0) {
aoqi@0 2036 char name[1*K];
aoqi@0 2037 Bytecodes::Code bc = (Bytecodes::Code)(counter & LSB_MASK);
aoqi@0 2038 if (bc_case == BC_CASE_LIMIT && (int)bc == 0)
aoqi@0 2039 bc = Bytecodes::_illegal;
aoqi@0 2040 sprintf(name, "%s/%s/%s",
aoqi@0 2041 trap_reason_name(reason),
aoqi@0 2042 trap_action_name(action),
aoqi@0 2043 Bytecodes::is_defined(bc)? Bytecodes::name(bc): "other");
aoqi@0 2044 juint r = counter >> LSB_BITS;
aoqi@0 2045 tty->print_cr(" %40s: " UINT32_FORMAT " (%.1f%%)", name, r, (r * 100.0) / total);
aoqi@0 2046 account -= r;
aoqi@0 2047 }
aoqi@0 2048 }
aoqi@0 2049 }
aoqi@0 2050 }
aoqi@0 2051 if (account != 0) {
aoqi@0 2052 PRINT_STAT_LINE("unaccounted", account);
aoqi@0 2053 }
aoqi@0 2054 #undef PRINT_STAT_LINE
aoqi@0 2055 if (xtty != NULL) xtty->tail("statistics");
aoqi@0 2056 }
aoqi@0 2057 }
aoqi@0 2058 #else // COMPILER2 || SHARK
aoqi@0 2059
aoqi@0 2060
aoqi@0 2061 // Stubs for C1 only system.
aoqi@0 2062 bool Deoptimization::trap_state_is_recompiled(int trap_state) {
aoqi@0 2063 return false;
aoqi@0 2064 }
aoqi@0 2065
aoqi@0 2066 const char* Deoptimization::trap_reason_name(int reason) {
aoqi@0 2067 return "unknown";
aoqi@0 2068 }
aoqi@0 2069
aoqi@0 2070 void Deoptimization::print_statistics() {
aoqi@0 2071 // no output
aoqi@0 2072 }
aoqi@0 2073
aoqi@0 2074 void
aoqi@0 2075 Deoptimization::update_method_data_from_interpreter(MethodData* trap_mdo, int trap_bci, int reason) {
aoqi@0 2076 // no udpate
aoqi@0 2077 }
aoqi@0 2078
aoqi@0 2079 int Deoptimization::trap_state_has_reason(int trap_state, int reason) {
aoqi@0 2080 return 0;
aoqi@0 2081 }
aoqi@0 2082
aoqi@0 2083 void Deoptimization::gather_statistics(DeoptReason reason, DeoptAction action,
aoqi@0 2084 Bytecodes::Code bc) {
aoqi@0 2085 // no update
aoqi@0 2086 }
aoqi@0 2087
aoqi@0 2088 const char* Deoptimization::format_trap_state(char* buf, size_t buflen,
aoqi@0 2089 int trap_state) {
aoqi@0 2090 jio_snprintf(buf, buflen, "#%d", trap_state);
aoqi@0 2091 return buf;
aoqi@0 2092 }
aoqi@0 2093
aoqi@0 2094 #endif // COMPILER2 || SHARK

mercurial