src/share/vm/interpreter/bytecodeInterpreter.cpp

changeset 6470
abe03600372a
parent 6467
f3806614494a
child 6483
018b357638aa
     1.1 --- a/src/share/vm/interpreter/bytecodeInterpreter.cpp	Thu Sep 19 17:31:42 2013 +0200
     1.2 +++ b/src/share/vm/interpreter/bytecodeInterpreter.cpp	Sun Sep 15 15:28:58 2013 +0200
     1.3 @@ -28,6 +28,7 @@
     1.4  #include "interpreter/bytecodeHistogram.hpp"
     1.5  #include "interpreter/bytecodeInterpreter.hpp"
     1.6  #include "interpreter/bytecodeInterpreter.inline.hpp"
     1.7 +#include "interpreter/bytecodeInterpreterProfiling.hpp"
     1.8  #include "interpreter/interpreter.hpp"
     1.9  #include "interpreter/interpreterRuntime.hpp"
    1.10  #include "memory/resourceArea.hpp"
    1.11 @@ -142,19 +143,20 @@
    1.12   * is no entry point to do the transition to vm so we just
    1.13   * do it by hand here.
    1.14   */
    1.15 -#define VM_JAVA_ERROR_NO_JUMP(name, msg)                                          \
    1.16 +#define VM_JAVA_ERROR_NO_JUMP(name, msg, note_a_trap)                             \
    1.17      DECACHE_STATE();                                                              \
    1.18      SET_LAST_JAVA_FRAME();                                                        \
    1.19      {                                                                             \
    1.20 +       InterpreterRuntime::note_a_trap(THREAD, istate->method(), BCI());          \
    1.21         ThreadInVMfromJava trans(THREAD);                                          \
    1.22         Exceptions::_throw_msg(THREAD, __FILE__, __LINE__, name, msg);             \
    1.23      }                                                                             \
    1.24      RESET_LAST_JAVA_FRAME();                                                      \
    1.25      CACHE_STATE();
    1.26  
    1.27 -// Normal throw of a java error
    1.28 -#define VM_JAVA_ERROR(name, msg)                                                  \
    1.29 -    VM_JAVA_ERROR_NO_JUMP(name, msg)                                              \
    1.30 +// Normal throw of a java error.
    1.31 +#define VM_JAVA_ERROR(name, msg, note_a_trap)                                     \
    1.32 +    VM_JAVA_ERROR_NO_JUMP(name, msg, note_a_trap)                                 \
    1.33      goto handle_exception;
    1.34  
    1.35  #ifdef PRODUCT
    1.36 @@ -340,9 +342,25 @@
    1.37        if (UseLoopCounter) {                                                                         \
    1.38          bool do_OSR = UseOnStackReplacement;                                                        \
    1.39          mcs->backedge_counter()->increment();                                                       \
    1.40 -        if (do_OSR) do_OSR = mcs->backedge_counter()->reached_InvocationLimit();                    \
    1.41 +        if (ProfileInterpreter) {                                                                   \
    1.42 +          BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);                                   \
    1.43 +          /* Check for overflow against MDO count. */                                               \
    1.44 +          do_OSR = do_OSR                                                                           \
    1.45 +            && (mdo_last_branch_taken_count >= (uint)InvocationCounter::InterpreterBackwardBranchLimit)\
    1.46 +            /* When ProfileInterpreter is on, the backedge_count comes     */                       \
    1.47 +            /* from the methodDataOop, which value does not get reset on   */                       \
    1.48 +            /* the call to frequency_counter_overflow(). To avoid          */                       \
    1.49 +            /* excessive calls to the overflow routine while the method is */                       \
    1.50 +            /* being compiled, add a second test to make sure the overflow */                       \
    1.51 +            /* function is called only once every overflow_frequency.      */                       \
    1.52 +            && (!(mdo_last_branch_taken_count & 1023));                                             \
    1.53 +        } else {                                                                                    \
    1.54 +          /* check for overflow of backedge counter */                                              \
    1.55 +          do_OSR = do_OSR                                                                           \
    1.56 +            && mcs->invocation_counter()->reached_InvocationLimit(mcs->backedge_counter());         \
    1.57 +        }                                                                                           \
    1.58          if (do_OSR) {                                                                               \
    1.59 -          nmethod*  osr_nmethod;                                                                    \
    1.60 +          nmethod* osr_nmethod;                                                                     \
    1.61            OSR_REQUEST(osr_nmethod, branch_pc);                                                      \
    1.62            if (osr_nmethod != NULL && osr_nmethod->osr_entry_bci() != InvalidOSREntryBci) {          \
    1.63              intptr_t* buf;                                                                          \
    1.64 @@ -355,7 +373,6 @@
    1.65            }                                                                                         \
    1.66          }                                                                                           \
    1.67        }  /* UseCompiler ... */                                                                      \
    1.68 -      mcs->invocation_counter()->increment();                                                       \
    1.69        SAFEPOINT;                                                                                    \
    1.70      }
    1.71  
    1.72 @@ -388,17 +405,21 @@
    1.73  #undef CACHE_FRAME
    1.74  #define CACHE_FRAME()
    1.75  
    1.76 +// BCI() returns the current bytecode-index.
    1.77 +#undef  BCI
    1.78 +#define BCI()           ((int)(intptr_t)(pc - (intptr_t)istate->method()->code_base()))
    1.79 +
    1.80  /*
    1.81   * CHECK_NULL - Macro for throwing a NullPointerException if the object
    1.82   * passed is a null ref.
    1.83   * On some architectures/platforms it should be possible to do this implicitly
    1.84   */
    1.85  #undef CHECK_NULL
    1.86 -#define CHECK_NULL(obj_)                                                 \
    1.87 -    if ((obj_) == NULL) {                                                \
    1.88 -        VM_JAVA_ERROR(vmSymbols::java_lang_NullPointerException(), "");  \
    1.89 -    }                                                                    \
    1.90 -    VERIFY_OOP(obj_)
    1.91 +#define CHECK_NULL(obj_)                                                                       \
    1.92 +        if ((obj_) == NULL) {                                                                  \
    1.93 +          VM_JAVA_ERROR(vmSymbols::java_lang_NullPointerException(), "", note_nullCheck_trap); \
    1.94 +        }                                                                                      \
    1.95 +        VERIFY_OOP(obj_)
    1.96  
    1.97  #define VMdoubleConstZero() 0.0
    1.98  #define VMdoubleConstOne() 1.0
    1.99 @@ -635,9 +656,16 @@
   1.100           topOfStack < istate->stack_base(),
   1.101           "Stack top out of range");
   1.102  
   1.103 +#ifdef CC_INTERP_PROFILE
   1.104 +  // MethodData's last branch taken count.
   1.105 +  uint mdo_last_branch_taken_count = 0;
   1.106 +#else
   1.107 +  const uint mdo_last_branch_taken_count = 0;
   1.108 +#endif
   1.109 +
   1.110    switch (istate->msg()) {
   1.111      case initialize: {
   1.112 -      if (initialized++) ShouldNotReachHere(); // Only one initialize call
   1.113 +      if (initialized++) ShouldNotReachHere(); // Only one initialize call.
   1.114        _compiling = (UseCompiler || CountCompiledCalls);
   1.115  #ifdef VM_JVMTI
   1.116        _jvmti_interp_events = JvmtiExport::can_post_interpreter_events();
   1.117 @@ -656,15 +684,12 @@
   1.118            METHOD->increment_interpreter_invocation_count(THREAD);
   1.119          }
   1.120          mcs->invocation_counter()->increment();
   1.121 -        if (mcs->invocation_counter()->reached_InvocationLimit()) {
   1.122 -            CALL_VM((void)InterpreterRuntime::frequency_counter_overflow(THREAD, NULL), handle_exception);
   1.123 -
   1.124 -            // We no longer retry on a counter overflow
   1.125 -
   1.126 -            // istate->set_msg(retry_method);
   1.127 -            // THREAD->clr_do_not_unlock();
   1.128 -            // return;
   1.129 +        if (mcs->invocation_counter()->reached_InvocationLimit(mcs->backedge_counter())) {
   1.130 +          CALL_VM((void)InterpreterRuntime::frequency_counter_overflow(THREAD, NULL), handle_exception);
   1.131 +          // We no longer retry on a counter overflow.
   1.132          }
   1.133 +        // Get or create profile data. Check for pending (async) exceptions.
   1.134 +        BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
   1.135          SAFEPOINT;
   1.136        }
   1.137  
   1.138 @@ -686,8 +711,7 @@
   1.139        }
   1.140  #endif // HACK
   1.141  
   1.142 -
   1.143 -      // lock method if synchronized
   1.144 +      // Lock method if synchronized.
   1.145        if (METHOD->is_synchronized()) {
   1.146          // oop rcvr = locals[0].j.r;
   1.147          oop rcvr;
   1.148 @@ -697,7 +721,7 @@
   1.149            rcvr = LOCALS_OBJECT(0);
   1.150            VERIFY_OOP(rcvr);
   1.151          }
   1.152 -        // The initial monitor is ours for the taking
   1.153 +        // The initial monitor is ours for the taking.
   1.154          // Monitor not filled in frame manager any longer as this caused race condition with biased locking.
   1.155          BasicObjectLock* mon = &istate->monitor_base()[-1];
   1.156          mon->set_obj(rcvr);
   1.157 @@ -803,6 +827,12 @@
   1.158        // clear the message so we don't confuse ourselves later
   1.159        assert(THREAD->pop_frame_in_process(), "wrong frame pop state");
   1.160        istate->set_msg(no_request);
   1.161 +      if (_compiling) {
   1.162 +        // Set MDX back to the ProfileData of the invoke bytecode that will be
   1.163 +        // restarted.
   1.164 +        SET_MDX(NULL);
   1.165 +        BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
   1.166 +      }
   1.167        THREAD->clr_pop_frame_in_process();
   1.168        goto run;
   1.169      }
   1.170 @@ -836,6 +866,11 @@
   1.171        if (THREAD->has_pending_exception()) goto handle_exception;
   1.172        // Update the pc by the saved amount of the invoke bytecode size
   1.173        UPDATE_PC(istate->bcp_advance());
   1.174 +
   1.175 +      if (_compiling) {
   1.176 +        // Get or create profile data. Check for pending (async) exceptions.
   1.177 +        BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
   1.178 +      }
   1.179        goto run;
   1.180      }
   1.181  
   1.182 @@ -843,6 +878,11 @@
   1.183        // Returned from an opcode that will reexecute. Deopt was
   1.184        // a result of a PopFrame request.
   1.185        //
   1.186 +
   1.187 +      if (_compiling) {
   1.188 +        // Get or create profile data. Check for pending (async) exceptions.
   1.189 +        BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
   1.190 +      }
   1.191        goto run;
   1.192      }
   1.193  
   1.194 @@ -865,6 +905,11 @@
   1.195        }
   1.196        UPDATE_PC(Bytecodes::length_at(METHOD, pc));
   1.197        if (THREAD->has_pending_exception()) goto handle_exception;
   1.198 +
   1.199 +      if (_compiling) {
   1.200 +        // Get or create profile data. Check for pending (async) exceptions.
   1.201 +        BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
   1.202 +      }
   1.203        goto run;
   1.204      }
   1.205      case got_monitors: {
   1.206 @@ -1115,6 +1160,11 @@
   1.207            uint16_t reg = Bytes::get_Java_u2(pc + 2);
   1.208  
   1.209            opcode = pc[1];
   1.210 +
   1.211 +          // Wide and it's sub-bytecode are counted as separate instructions. If we
   1.212 +          // don't account for this here, the bytecode trace skips the next bytecode.
   1.213 +          DO_UPDATE_INSTRUCTION_COUNT(opcode);
   1.214 +
   1.215            switch(opcode) {
   1.216                case Bytecodes::_aload:
   1.217                    VERIFY_OOP(LOCALS_OBJECT(reg));
   1.218 @@ -1158,10 +1208,13 @@
   1.219                    UPDATE_PC_AND_CONTINUE(6);
   1.220                }
   1.221                case Bytecodes::_ret:
   1.222 +                  // Profile ret.
   1.223 +                  BI_PROFILE_UPDATE_RET(/*bci=*/((int)(intptr_t)(LOCALS_ADDR(reg))));
   1.224 +                  // Now, update the pc.
   1.225                    pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(reg));
   1.226                    UPDATE_PC_AND_CONTINUE(0);
   1.227                default:
   1.228 -                  VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode");
   1.229 +                  VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode", note_no_trap);
   1.230            }
   1.231        }
   1.232  
   1.233 @@ -1242,7 +1295,7 @@
   1.234        CASE(_i##opcname):                                                \
   1.235            if (test && (STACK_INT(-1) == 0)) {                           \
   1.236                VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
   1.237 -                            "/ by zero");                               \
   1.238 +                            "/ by zero", note_div0Check_trap);          \
   1.239            }                                                             \
   1.240            SET_STACK_INT(VMint##opname(STACK_INT(-2),                    \
   1.241                                        STACK_INT(-1)),                   \
   1.242 @@ -1254,7 +1307,7 @@
   1.243              jlong l1 = STACK_LONG(-1);                                  \
   1.244              if (VMlongEqz(l1)) {                                        \
   1.245                VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
   1.246 -                            "/ by long zero");                          \
   1.247 +                            "/ by long zero", note_div0Check_trap);     \
   1.248              }                                                           \
   1.249            }                                                             \
   1.250            /* First long at (-1,-2) next long at (-3,-4) */              \
   1.251 @@ -1467,17 +1520,23 @@
   1.252  
   1.253  #define COMPARISON_OP(name, comparison)                                      \
   1.254        CASE(_if_icmp##name): {                                                \
   1.255 -          int skip = (STACK_INT(-2) comparison STACK_INT(-1))                \
   1.256 +          const bool cmp = (STACK_INT(-2) comparison STACK_INT(-1));         \
   1.257 +          int skip = cmp                                                     \
   1.258                        ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
   1.259            address branch_pc = pc;                                            \
   1.260 +          /* Profile branch. */                                              \
   1.261 +          BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp);                        \
   1.262            UPDATE_PC_AND_TOS(skip, -2);                                       \
   1.263            DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
   1.264            CONTINUE;                                                          \
   1.265        }                                                                      \
   1.266        CASE(_if##name): {                                                     \
   1.267 -          int skip = (STACK_INT(-1) comparison 0)                            \
   1.268 +          const bool cmp = (STACK_INT(-1) comparison 0);                     \
   1.269 +          int skip = cmp                                                     \
   1.270                        ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
   1.271            address branch_pc = pc;                                            \
   1.272 +          /* Profile branch. */                                              \
   1.273 +          BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp);                        \
   1.274            UPDATE_PC_AND_TOS(skip, -1);                                       \
   1.275            DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
   1.276            CONTINUE;                                                          \
   1.277 @@ -1486,9 +1545,12 @@
   1.278  #define COMPARISON_OP2(name, comparison)                                     \
   1.279        COMPARISON_OP(name, comparison)                                        \
   1.280        CASE(_if_acmp##name): {                                                \
   1.281 -          int skip = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1))          \
   1.282 +          const bool cmp = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1));   \
   1.283 +          int skip = cmp                                                     \
   1.284                         ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;            \
   1.285            address branch_pc = pc;                                            \
   1.286 +          /* Profile branch. */                                              \
   1.287 +          BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp);                        \
   1.288            UPDATE_PC_AND_TOS(skip, -2);                                       \
   1.289            DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
   1.290            CONTINUE;                                                          \
   1.291 @@ -1496,9 +1558,12 @@
   1.292  
   1.293  #define NULL_COMPARISON_NOT_OP(name)                                         \
   1.294        CASE(_if##name): {                                                     \
   1.295 -          int skip = (!(STACK_OBJECT(-1) == NULL))                           \
   1.296 +          const bool cmp = (!(STACK_OBJECT(-1) == NULL));                    \
   1.297 +          int skip = cmp                                                     \
   1.298                        ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
   1.299            address branch_pc = pc;                                            \
   1.300 +          /* Profile branch. */                                              \
   1.301 +          BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp);                        \
   1.302            UPDATE_PC_AND_TOS(skip, -1);                                       \
   1.303            DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
   1.304            CONTINUE;                                                          \
   1.305 @@ -1506,9 +1571,12 @@
   1.306  
   1.307  #define NULL_COMPARISON_OP(name)                                             \
   1.308        CASE(_if##name): {                                                     \
   1.309 -          int skip = ((STACK_OBJECT(-1) == NULL))                            \
   1.310 +          const bool cmp = ((STACK_OBJECT(-1) == NULL));                     \
   1.311 +          int skip = cmp                                                     \
   1.312                        ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3;             \
   1.313            address branch_pc = pc;                                            \
   1.314 +          /* Profile branch. */                                              \
   1.315 +          BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp);                        \
   1.316            UPDATE_PC_AND_TOS(skip, -1);                                       \
   1.317            DO_BACKEDGE_CHECKS(skip, branch_pc);                               \
   1.318            CONTINUE;                                                          \
   1.319 @@ -1531,30 +1599,42 @@
   1.320            int32_t  high = Bytes::get_Java_u4((address)&lpc[2]);
   1.321            int32_t  skip;
   1.322            key -= low;
   1.323 -          skip = ((uint32_t) key > (uint32_t)(high - low))
   1.324 -                      ? Bytes::get_Java_u4((address)&lpc[0])
   1.325 -                      : Bytes::get_Java_u4((address)&lpc[key + 3]);
   1.326 -          // Does this really need a full backedge check (osr?)
   1.327 +          if (((uint32_t) key > (uint32_t)(high - low))) {
   1.328 +            key = -1;
   1.329 +            skip = Bytes::get_Java_u4((address)&lpc[0]);
   1.330 +          } else {
   1.331 +            skip = Bytes::get_Java_u4((address)&lpc[key + 3]);
   1.332 +          }
   1.333 +          // Profile switch.
   1.334 +          BI_PROFILE_UPDATE_SWITCH(/*switch_index=*/key);
   1.335 +          // Does this really need a full backedge check (osr)?
   1.336            address branch_pc = pc;
   1.337            UPDATE_PC_AND_TOS(skip, -1);
   1.338            DO_BACKEDGE_CHECKS(skip, branch_pc);
   1.339            CONTINUE;
   1.340        }
   1.341  
   1.342 -      /* Goto pc whose table entry matches specified key */
   1.343 +      /* Goto pc whose table entry matches specified key. */
   1.344  
   1.345        CASE(_lookupswitch): {
   1.346            jint* lpc  = (jint*)VMalignWordUp(pc+1);
   1.347            int32_t  key  = STACK_INT(-1);
   1.348            int32_t  skip = Bytes::get_Java_u4((address) lpc); /* default amount */
   1.349 +          // Remember index.
   1.350 +          int      index = -1;
   1.351 +          int      newindex = 0;
   1.352            int32_t  npairs = Bytes::get_Java_u4((address) &lpc[1]);
   1.353            while (--npairs >= 0) {
   1.354 -              lpc += 2;
   1.355 -              if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) {
   1.356 -                  skip = Bytes::get_Java_u4((address)&lpc[1]);
   1.357 -                  break;
   1.358 -              }
   1.359 +            lpc += 2;
   1.360 +            if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) {
   1.361 +              skip = Bytes::get_Java_u4((address)&lpc[1]);
   1.362 +              index = newindex;
   1.363 +              break;
   1.364 +            }
   1.365 +            newindex += 1;
   1.366            }
   1.367 +          // Profile switch.
   1.368 +          BI_PROFILE_UPDATE_SWITCH(/*switch_index=*/index);
   1.369            address branch_pc = pc;
   1.370            UPDATE_PC_AND_TOS(skip, -1);
   1.371            DO_BACKEDGE_CHECKS(skip, branch_pc);
   1.372 @@ -1639,7 +1719,7 @@
   1.373        if ((uint32_t)index >= (uint32_t)arrObj->length()) {                     \
   1.374            sprintf(message, "%d", index);                                       \
   1.375            VM_JAVA_ERROR(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), \
   1.376 -                        message);                                              \
   1.377 +                        message, note_rangeCheck_trap);                        \
   1.378        }
   1.379  
   1.380        /* 32-bit loads. These handle conversion from < 32-bit types */
   1.381 @@ -1713,15 +1793,22 @@
   1.382            // arrObj, index are set
   1.383            if (rhsObject != NULL) {
   1.384              /* Check assignability of rhsObject into arrObj */
   1.385 -            Klass* rhsKlassOop = rhsObject->klass(); // EBX (subclass)
   1.386 -            Klass* elemKlassOop = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX
   1.387 +            Klass* rhsKlass = rhsObject->klass(); // EBX (subclass)
   1.388 +            Klass* elemKlass = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX
   1.389              //
   1.390              // Check for compatibilty. This check must not GC!!
   1.391              // Seems way more expensive now that we must dispatch
   1.392              //
   1.393 -            if (rhsKlassOop != elemKlassOop && !rhsKlassOop->is_subtype_of(elemKlassOop)) { // ebx->is...
   1.394 -              VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "");
   1.395 +            if (rhsKlass != elemKlass && !rhsKlass->is_subtype_of(elemKlass)) { // ebx->is...
   1.396 +              // Decrement counter if subtype check failed.
   1.397 +              BI_PROFILE_SUBTYPECHECK_FAILED(rhsKlass);
   1.398 +              VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "", note_arrayCheck_trap);
   1.399              }
   1.400 +            // Profile checkcast with null_seen and receiver.
   1.401 +            BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/false, rhsKlass);
   1.402 +          } else {
   1.403 +            // Profile checkcast with null_seen and receiver.
   1.404 +            BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/true, NULL);
   1.405            }
   1.406            ((objArrayOopDesc *) arrObj)->obj_at_put(index, rhsObject);
   1.407            UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);
   1.408 @@ -2119,10 +2206,14 @@
   1.409              if (UseTLAB) {
   1.410                result = (oop) THREAD->tlab().allocate(obj_size);
   1.411              }
   1.412 +            // Disable non-TLAB-based fast-path, because profiling requires that all
   1.413 +            // allocations go through InterpreterRuntime::_new() if THREAD->tlab().allocate
   1.414 +            // returns NULL.
   1.415 +#ifndef CC_INTERP_PROFILE
   1.416              if (result == NULL) {
   1.417                need_zero = true;
   1.418                // Try allocate in shared eden
   1.419 -        retry:
   1.420 +            retry:
   1.421                HeapWord* compare_to = *Universe::heap()->top_addr();
   1.422                HeapWord* new_top = compare_to + obj_size;
   1.423                if (new_top <= *Universe::heap()->end_addr()) {
   1.424 @@ -2132,6 +2223,7 @@
   1.425                  result = (oop) compare_to;
   1.426                }
   1.427              }
   1.428 +#endif
   1.429              if (result != NULL) {
   1.430                // Initialize object (if nonzero size and need) and then the header
   1.431                if (need_zero ) {
   1.432 @@ -2187,61 +2279,63 @@
   1.433            if (STACK_OBJECT(-1) != NULL) {
   1.434              VERIFY_OOP(STACK_OBJECT(-1));
   1.435              u2 index = Bytes::get_Java_u2(pc+1);
   1.436 -            if (ProfileInterpreter) {
   1.437 -              // needs Profile_checkcast QQQ
   1.438 -              ShouldNotReachHere();
   1.439 -            }
   1.440              // Constant pool may have actual klass or unresolved klass. If it is
   1.441 -            // unresolved we must resolve it
   1.442 +            // unresolved we must resolve it.
   1.443              if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
   1.444                CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
   1.445              }
   1.446              Klass* klassOf = (Klass*) METHOD->constants()->slot_at(index).get_klass();
   1.447 -            Klass* objKlassOop = STACK_OBJECT(-1)->klass(); //ebx
   1.448 +            Klass* objKlass = STACK_OBJECT(-1)->klass(); // ebx
   1.449              //
   1.450              // Check for compatibilty. This check must not GC!!
   1.451 -            // Seems way more expensive now that we must dispatch
   1.452 +            // Seems way more expensive now that we must dispatch.
   1.453              //
   1.454 -            if (objKlassOop != klassOf &&
   1.455 -                !objKlassOop->is_subtype_of(klassOf)) {
   1.456 +            if (objKlass != klassOf && !objKlass->is_subtype_of(klassOf)) {
   1.457 +              // Decrement counter at checkcast.
   1.458 +              BI_PROFILE_SUBTYPECHECK_FAILED(objKlass);
   1.459                ResourceMark rm(THREAD);
   1.460 -              const char* objName = objKlassOop->external_name();
   1.461 +              const char* objName = objKlass->external_name();
   1.462                const char* klassName = klassOf->external_name();
   1.463                char* message = SharedRuntime::generate_class_cast_message(
   1.464                  objName, klassName);
   1.465 -              VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message);
   1.466 +              VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message, note_classCheck_trap);
   1.467              }
   1.468 +            // Profile checkcast with null_seen and receiver.
   1.469 +            BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/false, objKlass);
   1.470            } else {
   1.471 -            if (UncommonNullCast) {
   1.472 -//              istate->method()->set_null_cast_seen();
   1.473 -// [RGV] Not sure what to do here!
   1.474 -
   1.475 -            }
   1.476 +            // Profile checkcast with null_seen and receiver.
   1.477 +            BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/true, NULL);
   1.478            }
   1.479            UPDATE_PC_AND_CONTINUE(3);
   1.480  
   1.481        CASE(_instanceof):
   1.482            if (STACK_OBJECT(-1) == NULL) {
   1.483              SET_STACK_INT(0, -1);
   1.484 +            // Profile instanceof with null_seen and receiver.
   1.485 +            BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/true, NULL);
   1.486            } else {
   1.487              VERIFY_OOP(STACK_OBJECT(-1));
   1.488              u2 index = Bytes::get_Java_u2(pc+1);
   1.489              // Constant pool may have actual klass or unresolved klass. If it is
   1.490 -            // unresolved we must resolve it
   1.491 +            // unresolved we must resolve it.
   1.492              if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
   1.493                CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
   1.494              }
   1.495              Klass* klassOf = (Klass*) METHOD->constants()->slot_at(index).get_klass();
   1.496 -            Klass* objKlassOop = STACK_OBJECT(-1)->klass();
   1.497 +            Klass* objKlass = STACK_OBJECT(-1)->klass();
   1.498              //
   1.499              // Check for compatibilty. This check must not GC!!
   1.500 -            // Seems way more expensive now that we must dispatch
   1.501 +            // Seems way more expensive now that we must dispatch.
   1.502              //
   1.503 -            if ( objKlassOop == klassOf || objKlassOop->is_subtype_of(klassOf)) {
   1.504 +            if ( objKlass == klassOf || objKlass->is_subtype_of(klassOf)) {
   1.505                SET_STACK_INT(1, -1);
   1.506              } else {
   1.507                SET_STACK_INT(0, -1);
   1.508 +              // Decrement counter at checkcast.
   1.509 +              BI_PROFILE_SUBTYPECHECK_FAILED(objKlass);
   1.510              }
   1.511 +            // Profile instanceof with null_seen and receiver.
   1.512 +            BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/false, objKlass);
   1.513            }
   1.514            UPDATE_PC_AND_CONTINUE(3);
   1.515  
   1.516 @@ -2384,6 +2478,9 @@
   1.517          istate->set_callee_entry_point(method->from_interpreted_entry());
   1.518          istate->set_bcp_advance(5);
   1.519  
   1.520 +        // Invokedynamic has got a call counter, just like an invokestatic -> increment!
   1.521 +        BI_PROFILE_UPDATE_CALL();
   1.522 +
   1.523          UPDATE_PC_AND_RETURN(0); // I'll be back...
   1.524        }
   1.525  
   1.526 @@ -2416,6 +2513,9 @@
   1.527          istate->set_callee_entry_point(method->from_interpreted_entry());
   1.528          istate->set_bcp_advance(3);
   1.529  
   1.530 +        // Invokehandle has got a call counter, just like a final call -> increment!
   1.531 +        BI_PROFILE_UPDATE_FINALCALL();
   1.532 +
   1.533          UPDATE_PC_AND_RETURN(0); // I'll be back...
   1.534        }
   1.535  
   1.536 @@ -2443,14 +2543,18 @@
   1.537            CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
   1.538            if (cache->is_vfinal()) {
   1.539              callee = cache->f2_as_vfinal_method();
   1.540 +            // Profile 'special case of invokeinterface' final call.
   1.541 +            BI_PROFILE_UPDATE_FINALCALL();
   1.542            } else {
   1.543 -            // get receiver
   1.544 +            // Get receiver.
   1.545              int parms = cache->parameter_size();
   1.546 -            // Same comments as invokevirtual apply here
   1.547 -            VERIFY_OOP(STACK_OBJECT(-parms));
   1.548 -            InstanceKlass* rcvrKlass = (InstanceKlass*)
   1.549 -                                 STACK_OBJECT(-parms)->klass();
   1.550 +            // Same comments as invokevirtual apply here.
   1.551 +            oop rcvr = STACK_OBJECT(-parms);
   1.552 +            VERIFY_OOP(rcvr);
   1.553 +            InstanceKlass* rcvrKlass = (InstanceKlass*)rcvr->klass();
   1.554              callee = (Method*) rcvrKlass->start_of_vtable()[ cache->f2_as_index()];
   1.555 +            // Profile 'special case of invokeinterface' virtual call.
   1.556 +            BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
   1.557            }
   1.558            istate->set_callee(callee);
   1.559            istate->set_callee_entry_point(callee->from_interpreted_entry());
   1.560 @@ -2481,15 +2585,18 @@
   1.561          // interface.  The link resolver checks this but only for the first
   1.562          // time this interface is called.
   1.563          if (i == int2->itable_length()) {
   1.564 -          VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "");
   1.565 +          VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "", note_no_trap);
   1.566          }
   1.567          int mindex = cache->f2_as_index();
   1.568          itableMethodEntry* im = ki->first_method_entry(rcvr->klass());
   1.569          callee = im[mindex].method();
   1.570          if (callee == NULL) {
   1.571 -          VM_JAVA_ERROR(vmSymbols::java_lang_AbstractMethodError(), "");
   1.572 +          VM_JAVA_ERROR(vmSymbols::java_lang_AbstractMethodError(), "", note_no_trap);
   1.573          }
   1.574  
   1.575 +        // Profile virtual call.
   1.576 +        BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
   1.577 +
   1.578          istate->set_callee(callee);
   1.579          istate->set_callee_entry_point(callee->from_interpreted_entry());
   1.580  #ifdef VM_JVMTI
   1.581 @@ -2521,8 +2628,11 @@
   1.582            Method* callee;
   1.583            if ((Bytecodes::Code)opcode == Bytecodes::_invokevirtual) {
   1.584              CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
   1.585 -            if (cache->is_vfinal()) callee = cache->f2_as_vfinal_method();
   1.586 -            else {
   1.587 +            if (cache->is_vfinal()) {
   1.588 +              callee = cache->f2_as_vfinal_method();
   1.589 +              // Profile final call.
   1.590 +              BI_PROFILE_UPDATE_FINALCALL();
   1.591 +            } else {
   1.592                // get receiver
   1.593                int parms = cache->parameter_size();
   1.594                // this works but needs a resourcemark and seems to create a vtable on every call:
   1.595 @@ -2531,8 +2641,9 @@
   1.596                // this fails with an assert
   1.597                // InstanceKlass* rcvrKlass = InstanceKlass::cast(STACK_OBJECT(-parms)->klass());
   1.598                // but this works
   1.599 -              VERIFY_OOP(STACK_OBJECT(-parms));
   1.600 -              InstanceKlass* rcvrKlass = (InstanceKlass*) STACK_OBJECT(-parms)->klass();
   1.601 +              oop rcvr = STACK_OBJECT(-parms);
   1.602 +              VERIFY_OOP(rcvr);
   1.603 +              InstanceKlass* rcvrKlass = (InstanceKlass*)rcvr->klass();
   1.604                /*
   1.605                  Executing this code in java.lang.String:
   1.606                      public String(char value[]) {
   1.607 @@ -2550,12 +2661,17 @@
   1.608  
   1.609                */
   1.610                callee = (Method*) rcvrKlass->start_of_vtable()[ cache->f2_as_index()];
   1.611 +              // Profile virtual call.
   1.612 +              BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
   1.613              }
   1.614            } else {
   1.615              if ((Bytecodes::Code)opcode == Bytecodes::_invokespecial) {
   1.616                CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
   1.617              }
   1.618              callee = cache->f1_as_method();
   1.619 +
   1.620 +            // Profile call.
   1.621 +            BI_PROFILE_UPDATE_CALL();
   1.622            }
   1.623  
   1.624            istate->set_callee(callee);
   1.625 @@ -2607,6 +2723,8 @@
   1.626        CASE(_goto):
   1.627        {
   1.628            int16_t offset = (int16_t)Bytes::get_Java_u2(pc + 1);
   1.629 +          // Profile jump.
   1.630 +          BI_PROFILE_UPDATE_JUMP();
   1.631            address branch_pc = pc;
   1.632            UPDATE_PC(offset);
   1.633            DO_BACKEDGE_CHECKS(offset, branch_pc);
   1.634 @@ -2623,6 +2741,8 @@
   1.635        CASE(_goto_w):
   1.636        {
   1.637            int32_t offset = Bytes::get_Java_u4(pc + 1);
   1.638 +          // Profile jump.
   1.639 +          BI_PROFILE_UPDATE_JUMP();
   1.640            address branch_pc = pc;
   1.641            UPDATE_PC(offset);
   1.642            DO_BACKEDGE_CHECKS(offset, branch_pc);
   1.643 @@ -2632,6 +2752,9 @@
   1.644        /* return from a jsr or jsr_w */
   1.645  
   1.646        CASE(_ret): {
   1.647 +          // Profile ret.
   1.648 +          BI_PROFILE_UPDATE_RET(/*bci=*/((int)(intptr_t)(LOCALS_ADDR(pc[1]))));
   1.649 +          // Now, update the pc.
   1.650            pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(pc[1]));
   1.651            UPDATE_PC_AND_CONTINUE(0);
   1.652        }
   1.653 @@ -2713,6 +2836,9 @@
   1.654        }
   1.655        // for AbortVMOnException flag
   1.656        NOT_PRODUCT(Exceptions::debug_check_abort(except_oop));
   1.657 +
   1.658 +      // Update profiling data.
   1.659 +      BI_PROFILE_ALIGN_TO_CURRENT_BCI();
   1.660        goto run;
   1.661      }
   1.662      if (TraceExceptions) {
   1.663 @@ -2920,7 +3046,7 @@
   1.664            oop rcvr = base->obj();
   1.665            if (rcvr == NULL) {
   1.666              if (!suppress_error) {
   1.667 -              VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "");
   1.668 +              VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "", note_nullCheck_trap);
   1.669                illegal_state_oop = THREAD->pending_exception();
   1.670                THREAD->clear_pending_exception();
   1.671              }
   1.672 @@ -3008,9 +3134,9 @@
   1.673      // A pending exception that was pending prior to a possible popping frame
   1.674      // overrides the popping frame.
   1.675      //
   1.676 -    assert(!suppress_error || suppress_error && illegal_state_oop() == NULL, "Error was not suppressed");
   1.677 +    assert(!suppress_error || (suppress_error && illegal_state_oop() == NULL), "Error was not suppressed");
   1.678      if (illegal_state_oop() != NULL || original_exception() != NULL) {
   1.679 -      // inform the frame manager we have no result
   1.680 +      // Inform the frame manager we have no result.
   1.681        istate->set_msg(throwing_exception);
   1.682        if (illegal_state_oop() != NULL)
   1.683          THREAD->set_pending_exception(illegal_state_oop(), NULL, 0);

mercurial