comparison ppc_patches/0201_C_interpreter-implement_bytecode_profiling.patch @ 4798:df79d76c17ab

Patch queue containing the ppc port. Applying this to the staging repository at tag hs25-b34 leads to the code contained in this repository. We will update the patches so that with the staging repo and the patches always a working hotspot for ppc can be built.
author Goetz
date Wed, 12 Jun 2013 15:55:20 +0200
parents
children edf2bb42e70f
comparison
equal deleted inserted replaced
-1:000000000000 0:6cd923ee3165
1 # HG changeset patch
2 # Parent 84fd980e69ee155f80ae36002f29703ea7d16205
3 C-interpreter: implement bytecode profiling.
4
5 diff -r 84fd980e69ee src/share/vm/interpreter/bytecodeInterpreter.cpp
6 --- a/src/share/vm/interpreter/bytecodeInterpreter.cpp Fri Jun 07 12:50:21 2013 +0200
7 +++ b/src/share/vm/interpreter/bytecodeInterpreter.cpp Fri Jun 07 12:51:22 2013 +0200
8 @@ -28,6 +28,7 @@
9 #include "interpreter/bytecodeHistogram.hpp"
10 #include "interpreter/bytecodeInterpreter.hpp"
11 #include "interpreter/bytecodeInterpreter.inline.hpp"
12 +#include "interpreter/bytecodeInterpreterProfiling.hpp"
13 #include "interpreter/interpreter.hpp"
14 #include "interpreter/interpreterRuntime.hpp"
15 #include "memory/cardTableModRefBS.hpp"
16 @@ -143,10 +144,11 @@
17 * is no entry point to do the transition to vm so we just
18 * do it by hand here.
19 */
20 -#define VM_JAVA_ERROR_NO_JUMP(name, msg) \
21 +#define VM_JAVA_ERROR_NO_JUMP(name, msg, note_a_trap) \
22 DECACHE_STATE(); \
23 SET_LAST_JAVA_FRAME(); \
24 { \
25 + InterpreterRuntime::note_a_trap(THREAD, istate->method(), BCI()); \
26 ThreadInVMfromJava trans(THREAD); \
27 Exceptions::_throw_msg(THREAD, __FILE__, __LINE__, name, msg); \
28 } \
29 @@ -154,8 +156,8 @@
30 CACHE_STATE();
31
32 // Normal throw of a java error
33 -#define VM_JAVA_ERROR(name, msg) \
34 - VM_JAVA_ERROR_NO_JUMP(name, msg) \
35 +#define VM_JAVA_ERROR(name, msg, note_a_trap) \
36 + VM_JAVA_ERROR_NO_JUMP(name, msg, note_a_trap) \
37 goto handle_exception;
38
39 #ifdef PRODUCT
40 @@ -346,7 +348,22 @@
41 if (UseLoopCounter) { \
42 bool do_OSR = UseOnStackReplacement; \
43 INCR_BACKEDGE_COUNT(mcs); \
44 - if (do_OSR) do_OSR = BACKEDGE_COUNT(mcs)->reached_InvocationLimit(); \
45 + if (ProfileInterpreter) { \
46 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception); \
47 + /* Check for overflow against MDO count. */ \
48 + do_OSR = do_OSR \
49 + && (mdo_last_branch_taken_count >= (uint)InvocationCounter::InterpreterBackwardBranchLimit)\
50 + /* When ProfileInterpreter is on, the backedge_count comes */ \
51 + /* from the methodDataOop, which value does not get reset on */ \
52 + /* the call to frequency_counter_overflow(). To avoid */ \
53 + /* excessive calls to the overflow routine while the method is */ \
54 + /* being compiled, add a second test to make sure the overflow */ \
55 + /* function is called only once every overflow_frequency. */ \
56 + && (!(mdo_last_branch_taken_count & 1023)); \
57 + } else { \
58 + /* check for overflow of backedge counter */ \
59 + do_OSR = do_OSR && INVOCATION_COUNT(mcs)->reached_InvocationLimit(BACKEDGE_COUNT(mcs)); \
60 + } \
61 if (do_OSR) { \
62 nmethod* osr_nmethod; \
63 OSR_REQUEST(osr_nmethod, branch_pc); \
64 @@ -359,7 +376,6 @@
65 } \
66 } \
67 } /* UseCompiler ... */ \
68 - mcs->invocation_counter()->increment(); \
69 SAFEPOINT; \
70 }
71
72 @@ -392,16 +408,20 @@
73 #undef CACHE_FRAME
74 #define CACHE_FRAME()
75
76 +// BCI() returns the current bytecode-index.
77 +#undef BCI
78 +#define BCI() ((int)(intptr_t)(pc - (intptr_t)istate->method()->code_base()))
79 +
80 /*
81 * CHECK_NULL - Macro for throwing a NullPointerException if the object
82 * passed is a null ref.
83 * On some architectures/platforms it should be possible to do this implicitly
84 */
85 #undef CHECK_NULL
86 -#define CHECK_NULL(obj_) \
87 - if ((obj_) == NULL) { \
88 - VM_JAVA_ERROR(vmSymbols::java_lang_NullPointerException(), ""); \
89 - } \
90 +#define CHECK_NULL(obj_) \
91 + if ((obj_) == NULL) { \
92 + VM_JAVA_ERROR(vmSymbols::java_lang_NullPointerException(), "", note_nullCheck_trap); \
93 + } \
94 VERIFY_OOP(obj_)
95
96 #define VMdoubleConstZero() 0.0
97 @@ -636,6 +656,13 @@
98 topOfStack < istate->stack_base(),
99 "Stack top out of range");
100
101 +#ifdef CC_INTERP_PROFILE
102 + // MethodData's last branch taken count.
103 + uint mdo_last_branch_taken_count = 0;
104 +#else
105 + const uint mdo_last_branch_taken_count = 0;
106 +#endif
107 +
108 switch (istate->msg()) {
109 case initialize: {
110 if (initialized++) ShouldNotReachHere(); // Only one initialize call
111 @@ -657,15 +684,12 @@
112 METHOD->increment_interpreter_invocation_count(THREAD);
113 }
114 INCR_INVOCATION_COUNT(mcs);
115 - if (INVOCATION_COUNT(mcs)->reached_InvocationLimit()) {
116 - CALL_VM((void)InterpreterRuntime::frequency_counter_overflow(THREAD, NULL), handle_exception);
117 -
118 - // We no longer retry on a counter overflow
119 -
120 - // istate->set_msg(retry_method);
121 - // THREAD->clr_do_not_unlock();
122 - // return;
123 + if (INVOCATION_COUNT(mcs)->reached_InvocationLimit(BACKEDGE_COUNT(mcs))) {
124 + CALL_VM((void)InterpreterRuntime::frequency_counter_overflow(THREAD, NULL), handle_exception);
125 + // We no longer retry on a counter overflow
126 }
127 + // Get or create profile data. Check for pending (async) exceptions.
128 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
129 SAFEPOINT;
130 }
131
132 @@ -806,9 +830,18 @@
133 case popping_frame: {
134 // returned from a java call to pop the frame, restart the call
135 // clear the message so we don't confuse ourselves later
136 - ShouldNotReachHere(); // we don't return this.
137 + // Commented out ShouldNotReachHere() below, because we do reach
138 + // here when the frame manager calls the interpreter loop after
139 + // popping the top frame.
140 + // ShouldNotReachHere(); // we don't return this.
141 assert(THREAD->pop_frame_in_process(), "wrong frame pop state");
142 istate->set_msg(no_request);
143 + if (_compiling) {
144 + // Set MDX back to the ProfileData of the invoke bytecode that will be
145 + // restarted.
146 + SET_MDX(NULL);
147 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
148 + }
149 THREAD->clr_pop_frame_in_process();
150 goto run;
151 }
152 @@ -842,6 +875,11 @@
153 if (THREAD->has_pending_exception()) goto handle_exception;
154 // Update the pc by the saved amount of the invoke bytecode size
155 UPDATE_PC(istate->bcp_advance());
156 +
157 + if (_compiling) {
158 + // Get or create profile data. Check for pending (async) exceptions.
159 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
160 + }
161 goto run;
162 }
163
164 @@ -849,6 +887,11 @@
165 // Returned from an opcode that will reexecute. Deopt was
166 // a result of a PopFrame request.
167 //
168 +
169 + if (_compiling) {
170 + // Get or create profile data. Check for pending (async) exceptions.
171 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
172 + }
173 goto run;
174 }
175
176 @@ -871,6 +914,11 @@
177 }
178 UPDATE_PC(Bytecodes::length_at(METHOD, pc));
179 if (THREAD->has_pending_exception()) goto handle_exception;
180 +
181 + if (_compiling) {
182 + // Get or create profile data. Check for pending (async) exceptions.
183 + BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
184 + }
185 goto run;
186 }
187 case got_monitors: {
188 @@ -1124,6 +1172,11 @@
189 uint16_t reg = Bytes::get_Java_u2(pc + 2);
190
191 opcode = pc[1];
192 +
193 + // Wide and it's sub-bytecode are counted as separate instructions. If we
194 + // don't account for this here, the bytecode trace skips the next bytecode.
195 + DO_UPDATE_INSTRUCTION_COUNT(opcode);
196 +
197 switch(opcode) {
198 case Bytecodes::_aload:
199 VERIFY_OOP(LOCALS_OBJECT(reg));
200 @@ -1167,10 +1220,13 @@
201 UPDATE_PC_AND_CONTINUE(6);
202 }
203 case Bytecodes::_ret:
204 + // Profile ret.
205 + BI_PROFILE_UPDATE_RET(/*bci=*/((int)(intptr_t)(LOCALS_ADDR(reg))));
206 + // Now, update the pc.
207 pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(reg));
208 UPDATE_PC_AND_CONTINUE(0);
209 default:
210 - VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode");
211 + VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode", note_no_trap);
212 }
213 }
214
215 @@ -1251,7 +1307,7 @@
216 CASE(_i##opcname): \
217 if (test && (STACK_INT(-1) == 0)) { \
218 VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
219 - "/ by zero"); \
220 + "/ by zero", note_div0Check_trap); \
221 } \
222 SET_STACK_INT(VMint##opname(STACK_INT(-2), \
223 STACK_INT(-1)), \
224 @@ -1263,7 +1319,7 @@
225 jlong l1 = STACK_LONG(-1); \
226 if (VMlongEqz(l1)) { \
227 VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
228 - "/ by long zero"); \
229 + "/ by long zero", note_div0Check_trap); \
230 } \
231 } \
232 /* First long at (-1,-2) next long at (-3,-4) */ \
233 @@ -1476,17 +1532,23 @@
234
235 #define COMPARISON_OP(name, comparison) \
236 CASE(_if_icmp##name): { \
237 - int skip = (STACK_INT(-2) comparison STACK_INT(-1)) \
238 + const bool cmp = (STACK_INT(-2) comparison STACK_INT(-1)); \
239 + int skip = cmp \
240 ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
241 address branch_pc = pc; \
242 + /* Profile branch. */ \
243 + BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \
244 UPDATE_PC_AND_TOS(skip, -2); \
245 DO_BACKEDGE_CHECKS(skip, branch_pc); \
246 CONTINUE; \
247 } \
248 CASE(_if##name): { \
249 - int skip = (STACK_INT(-1) comparison 0) \
250 + const bool cmp = (STACK_INT(-1) comparison 0); \
251 + int skip = cmp \
252 ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
253 address branch_pc = pc; \
254 + /* Profile branch. */ \
255 + BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \
256 UPDATE_PC_AND_TOS(skip, -1); \
257 DO_BACKEDGE_CHECKS(skip, branch_pc); \
258 CONTINUE; \
259 @@ -1495,9 +1557,12 @@
260 #define COMPARISON_OP2(name, comparison) \
261 COMPARISON_OP(name, comparison) \
262 CASE(_if_acmp##name): { \
263 - int skip = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1)) \
264 + const bool cmp = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1)); \
265 + int skip = cmp \
266 ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
267 address branch_pc = pc; \
268 + /* Profile branch. */ \
269 + BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \
270 UPDATE_PC_AND_TOS(skip, -2); \
271 DO_BACKEDGE_CHECKS(skip, branch_pc); \
272 CONTINUE; \
273 @@ -1505,9 +1570,12 @@
274
275 #define NULL_COMPARISON_NOT_OP(name) \
276 CASE(_if##name): { \
277 - int skip = (!(STACK_OBJECT(-1) == NULL)) \
278 + const bool cmp = (!(STACK_OBJECT(-1) == NULL)); \
279 + int skip = cmp \
280 ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
281 address branch_pc = pc; \
282 + /* Profile branch. */ \
283 + BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \
284 UPDATE_PC_AND_TOS(skip, -1); \
285 DO_BACKEDGE_CHECKS(skip, branch_pc); \
286 CONTINUE; \
287 @@ -1515,9 +1583,12 @@
288
289 #define NULL_COMPARISON_OP(name) \
290 CASE(_if##name): { \
291 - int skip = ((STACK_OBJECT(-1) == NULL)) \
292 + const bool cmp = ((STACK_OBJECT(-1) == NULL)); \
293 + int skip = cmp \
294 ? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
295 address branch_pc = pc; \
296 + /* Profile branch. */ \
297 + BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \
298 UPDATE_PC_AND_TOS(skip, -1); \
299 DO_BACKEDGE_CHECKS(skip, branch_pc); \
300 CONTINUE; \
301 @@ -1540,9 +1611,14 @@
302 int32_t high = Bytes::get_Java_u4((address)&lpc[2]);
303 int32_t skip;
304 key -= low;
305 - skip = ((uint32_t) key > (uint32_t)(high - low))
306 - ? Bytes::get_Java_u4((address)&lpc[0])
307 - : Bytes::get_Java_u4((address)&lpc[key + 3]);
308 + if (((uint32_t) key > (uint32_t)(high - low))) {
309 + key = -1;
310 + skip = Bytes::get_Java_u4((address)&lpc[0]);
311 + } else {
312 + skip = Bytes::get_Java_u4((address)&lpc[key + 3]);
313 + }
314 + // Profile switch.
315 + BI_PROFILE_UPDATE_SWITCH(/*switch_index=*/key);
316 // Does this really need a full backedge check (osr?)
317 address branch_pc = pc;
318 UPDATE_PC_AND_TOS(skip, -1);
319 @@ -1556,14 +1632,21 @@
320 jint* lpc = (jint*)VMalignWordUp(pc+1);
321 int32_t key = STACK_INT(-1);
322 int32_t skip = Bytes::get_Java_u4((address) lpc); /* default amount */
323 + // Remember index.
324 + int index = -1;
325 + int newindex = 0;
326 int32_t npairs = Bytes::get_Java_u4((address) &lpc[1]);
327 while (--npairs >= 0) {
328 - lpc += 2;
329 - if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) {
330 - skip = Bytes::get_Java_u4((address)&lpc[1]);
331 - break;
332 - }
333 + lpc += 2;
334 + if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) {
335 + skip = Bytes::get_Java_u4((address)&lpc[1]);
336 + index = newindex;
337 + break;
338 + }
339 + newindex += 1;
340 }
341 + // Profile switch.
342 + BI_PROFILE_UPDATE_SWITCH(/*switch_index=*/index);
343 address branch_pc = pc;
344 UPDATE_PC_AND_TOS(skip, -1);
345 DO_BACKEDGE_CHECKS(skip, branch_pc);
346 @@ -1648,7 +1731,7 @@
347 if ((uint32_t)index >= (uint32_t)arrObj->length()) { \
348 sprintf(message, "%d", index); \
349 VM_JAVA_ERROR(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), \
350 - message); \
351 + message, note_rangeCheck_trap); \
352 }
353
354 /* 32-bit loads. These handle conversion from < 32-bit types */
355 @@ -1729,15 +1812,22 @@
356 // arrObj, index are set
357 if (rhsObject != NULL) {
358 /* Check assignability of rhsObject into arrObj */
359 - Klass* rhsKlassOop = rhsObject->klass(); // EBX (subclass)
360 - Klass* elemKlassOop = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX
361 + Klass* rhsKlass = rhsObject->klass(); // EBX (subclass)
362 + Klass* elemKlass = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX
363 //
364 // Check for compatibilty. This check must not GC!!
365 // Seems way more expensive now that we must dispatch
366 //
367 - if (rhsKlassOop != elemKlassOop && !rhsKlassOop->is_subtype_of(elemKlassOop)) { // ebx->is...
368 - VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "");
369 + if (rhsKlass != elemKlass && !rhsKlass->is_subtype_of(elemKlass)) { // ebx->is...
370 + // Decrement counter if subtype check failed.
371 + BI_PROFILE_SUBTYPECHECK_FAILED(rhsKlass);
372 + VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "", note_arrayCheck_trap);
373 }
374 + // Profile checkcast with null_seen and receiver.
375 + BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/false, rhsKlass);
376 + } else {
377 + // Profile checkcast with null_seen and receiver.
378 + BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/true, NULL);
379 }
380 // G1GC port. Use accessor instead of storing manually.
381 // Takes care of write barriers internally and replaces the code above.
382 @@ -2139,10 +2229,14 @@
383 if (UseTLAB) {
384 result = (oop) THREAD->tlab().allocate(obj_size);
385 }
386 + // Disable non-TLAB-based fast-path, because profiling requires that all
387 + // allocations go through InterpreterRuntime::_new() if THREAD->tlab().allocate
388 + // returns NULL.
389 +#ifndef CC_INTERP_PROFILE
390 if (result == NULL) {
391 need_zero = true;
392 // Try allocate in shared eden
393 - retry:
394 + retry:
395 HeapWord* compare_to = *Universe::heap()->top_addr();
396 HeapWord* new_top = compare_to + obj_size;
397 if (new_top <= *Universe::heap()->end_addr()) {
398 @@ -2152,6 +2246,7 @@
399 result = (oop) compare_to;
400 }
401 }
402 +#endif
403 if (result != NULL) {
404 // Initialize object (if nonzero size and need) and then the header
405 if (need_zero ) {
406 @@ -2207,42 +2302,40 @@
407 if (STACK_OBJECT(-1) != NULL) {
408 VERIFY_OOP(STACK_OBJECT(-1));
409 u2 index = Bytes::get_Java_u2(pc+1);
410 - if (ProfileInterpreter) {
411 - // needs Profile_checkcast QQQ
412 - ShouldNotReachHere();
413 - }
414 // Constant pool may have actual klass or unresolved klass. If it is
415 // unresolved we must resolve it
416 if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
417 CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
418 }
419 Klass* klassOf = (Klass*) METHOD->constants()->slot_at(index).get_klass();
420 - Klass* objKlassOop = STACK_OBJECT(-1)->klass(); //ebx
421 + Klass* objKlass = STACK_OBJECT(-1)->klass(); //ebx
422 //
423 // Check for compatibilty. This check must not GC!!
424 // Seems way more expensive now that we must dispatch
425 //
426 - if (objKlassOop != klassOf &&
427 - !objKlassOop->is_subtype_of(klassOf)) {
428 + if (objKlass != klassOf && !objKlass->is_subtype_of(klassOf)) {
429 + // Decrement counter at checkcast.
430 + BI_PROFILE_SUBTYPECHECK_FAILED(objKlass);
431 ResourceMark rm(THREAD);
432 - const char* objName = objKlassOop->external_name();
433 + const char* objName = objKlass->external_name();
434 const char* klassName = klassOf->external_name();
435 char* message = SharedRuntime::generate_class_cast_message(
436 objName, klassName);
437 - VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message);
438 + VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message, note_classCheck_trap);
439 }
440 + // Profile checkcast with null_seen and receiver.
441 + BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/false, objKlass);
442 } else {
443 - if (UncommonNullCast) {
444 -// istate->method()->set_null_cast_seen();
445 -// [RGV] Not sure what to do here!
446 -
447 - }
448 + // Profile checkcast with null_seen and receiver.
449 + BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/true, NULL);
450 }
451 UPDATE_PC_AND_CONTINUE(3);
452
453 CASE(_instanceof):
454 if (STACK_OBJECT(-1) == NULL) {
455 SET_STACK_INT(0, -1);
456 + // Profile instanceof with null_seen and receiver.
457 + BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/true, NULL);
458 } else {
459 VERIFY_OOP(STACK_OBJECT(-1));
460 u2 index = Bytes::get_Java_u2(pc+1);
461 @@ -2252,16 +2345,20 @@
462 CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
463 }
464 Klass* klassOf = (Klass*) METHOD->constants()->slot_at(index).get_klass();
465 - Klass* objKlassOop = STACK_OBJECT(-1)->klass();
466 + Klass* objKlass = STACK_OBJECT(-1)->klass();
467 //
468 // Check for compatibilty. This check must not GC!!
469 // Seems way more expensive now that we must dispatch
470 //
471 - if ( objKlassOop == klassOf || objKlassOop->is_subtype_of(klassOf)) {
472 + if ( objKlass == klassOf || objKlass->is_subtype_of(klassOf)) {
473 SET_STACK_INT(1, -1);
474 } else {
475 SET_STACK_INT(0, -1);
476 + // Decrement counter at checkcast.
477 + BI_PROFILE_SUBTYPECHECK_FAILED(objKlass);
478 }
479 + // Profile instanceof with null_seen and receiver.
480 + BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/false, objKlass);
481 }
482 UPDATE_PC_AND_CONTINUE(3);
483
484 @@ -2404,6 +2501,9 @@
485 istate->set_callee_entry_point(method->from_interpreted_entry());
486 istate->set_bcp_advance(5);
487
488 + // Invokedynamic has got a call counter, just like an invokestatic -> increment!
489 + BI_PROFILE_UPDATE_CALL();
490 +
491 UPDATE_PC_AND_RETURN(0); // I'll be back...
492 }
493
494 @@ -2437,6 +2537,9 @@
495 istate->set_callee_entry_point(method->from_interpreted_entry());
496 istate->set_bcp_advance(3);
497
498 + // Invokehandle has got a call counter, just like a final call -> increment!
499 + BI_PROFILE_UPDATE_FINALCALL();
500 +
501 UPDATE_PC_AND_RETURN(0); // I'll be back...
502 }
503
504 @@ -2464,14 +2567,18 @@
505 CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
506 if (cache->is_vfinal()) {
507 callee = cache->f2_as_vfinal_method();
508 + // Profile 'special case of invokeinterface' final call.
509 + BI_PROFILE_UPDATE_FINALCALL();
510 } else {
511 // get receiver
512 int parms = cache->parameter_size();
513 // Same comments as invokevirtual apply here
514 - VERIFY_OOP(STACK_OBJECT(-parms));
515 - InstanceKlass* rcvrKlass = (InstanceKlass*)
516 - STACK_OBJECT(-parms)->klass();
517 + oop rcvr = STACK_OBJECT(-parms);
518 + VERIFY_OOP(rcvr);
519 + InstanceKlass* rcvrKlass = (InstanceKlass*)rcvr->klass();
520 callee = (Method*) rcvrKlass->start_of_vtable()[ cache->f2_as_index()];
521 + // Profile 'special case of invokeinterface' virtual call.
522 + BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
523 }
524 istate->set_callee(callee);
525 istate->set_callee_entry_point(callee->from_interpreted_entry());
526 @@ -2502,15 +2609,18 @@
527 // interface. The link resolver checks this but only for the first
528 // time this interface is called.
529 if (i == int2->itable_length()) {
530 - VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "");
531 + VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "", note_no_trap);
532 }
533 int mindex = cache->f2_as_index();
534 itableMethodEntry* im = ki->first_method_entry(rcvr->klass());
535 callee = im[mindex].method();
536 if (callee == NULL) {
537 - VM_JAVA_ERROR(vmSymbols::java_lang_AbstractMethodError(), "");
538 + VM_JAVA_ERROR(vmSymbols::java_lang_AbstractMethodError(), "", note_no_trap);
539 }
540
541 + // Profile virtual call.
542 + BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
543 +
544 istate->set_callee(callee);
545 istate->set_callee_entry_point(callee->from_interpreted_entry());
546 #ifdef VM_JVMTI
547 @@ -2542,8 +2652,11 @@
548 Method* callee;
549 if ((Bytecodes::Code)opcode == Bytecodes::_invokevirtual) {
550 CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
551 - if (cache->is_vfinal()) callee = cache->f2_as_vfinal_method();
552 - else {
553 + if (cache->is_vfinal()) {
554 + callee = cache->f2_as_vfinal_method();
555 + // Profile final call.
556 + BI_PROFILE_UPDATE_FINALCALL();
557 + } else {
558 // get receiver
559 int parms = cache->parameter_size();
560 // this works but needs a resourcemark and seems to create a vtable on every call:
561 @@ -2552,8 +2665,9 @@
562 // this fails with an assert
563 // InstanceKlass* rcvrKlass = InstanceKlass::cast(STACK_OBJECT(-parms)->klass());
564 // but this works
565 - VERIFY_OOP(STACK_OBJECT(-parms));
566 - InstanceKlass* rcvrKlass = (InstanceKlass*) STACK_OBJECT(-parms)->klass();
567 + oop rcvr = STACK_OBJECT(-parms);
568 + VERIFY_OOP(rcvr);
569 + InstanceKlass* rcvrKlass = (InstanceKlass*)rcvr->klass();
570 /*
571 Executing this code in java.lang.String:
572 public String(char value[]) {
573 @@ -2571,12 +2685,17 @@
574
575 */
576 callee = (Method*) rcvrKlass->start_of_vtable()[ cache->f2_as_index()];
577 + // Profile virtual call.
578 + BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
579 }
580 } else {
581 if ((Bytecodes::Code)opcode == Bytecodes::_invokespecial) {
582 CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
583 }
584 callee = cache->f1_as_method();
585 +
586 + // Profile call.
587 + BI_PROFILE_UPDATE_CALL();
588 }
589
590 istate->set_callee(callee);
591 @@ -2628,6 +2747,8 @@
592 CASE(_goto):
593 {
594 int16_t offset = (int16_t)Bytes::get_Java_u2(pc + 1);
595 + // Profile jump.
596 + BI_PROFILE_UPDATE_JUMP();
597 address branch_pc = pc;
598 UPDATE_PC(offset);
599 DO_BACKEDGE_CHECKS(offset, branch_pc);
600 @@ -2644,6 +2765,8 @@
601 CASE(_goto_w):
602 {
603 int32_t offset = Bytes::get_Java_u4(pc + 1);
604 + // Profile jump.
605 + BI_PROFILE_UPDATE_JUMP();
606 address branch_pc = pc;
607 UPDATE_PC(offset);
608 DO_BACKEDGE_CHECKS(offset, branch_pc);
609 @@ -2653,6 +2776,9 @@
610 /* return from a jsr or jsr_w */
611
612 CASE(_ret): {
613 + // Profile ret.
614 + BI_PROFILE_UPDATE_RET(/*bci=*/((int)(intptr_t)(LOCALS_ADDR(pc[1]))));
615 + // now, update the pc
616 pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(pc[1]));
617 UPDATE_PC_AND_CONTINUE(0);
618 }
619 @@ -2734,6 +2860,9 @@
620 }
621 // for AbortVMOnException flag
622 NOT_PRODUCT(Exceptions::debug_check_abort(except_oop));
623 +
624 + // Update profiling data.
625 + BI_PROFILE_ALIGN_TO_CURRENT_BCI();
626 goto run;
627 }
628 if (TraceExceptions) {
629 @@ -2936,7 +3065,7 @@
630 oop rcvr = base->obj();
631 if (rcvr == NULL) {
632 if (!suppress_error) {
633 - VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "");
634 + VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "", note_nullCheck_trap);
635 illegal_state_oop = THREAD->pending_exception();
636 THREAD->clear_pending_exception();
637 }
638 @@ -3014,7 +3143,7 @@
639 // A pending exception that was pending prior to a possible popping frame
640 // overrides the popping frame.
641 //
642 - assert(!suppress_error || suppress_error && illegal_state_oop() == NULL, "Error was not suppressed");
643 + assert(!suppress_error || (suppress_error && illegal_state_oop() == NULL), "Error was not suppressed");
644 if (illegal_state_oop() != NULL || original_exception() != NULL) {
645 // inform the frame manager we have no result
646 istate->set_msg(throwing_exception);
647 diff -r 84fd980e69ee src/share/vm/interpreter/bytecodeInterpreterProfiling.hpp
648 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
649 +++ b/src/share/vm/interpreter/bytecodeInterpreterProfiling.hpp Fri Jun 07 12:51:22 2013 +0200
650 @@ -0,0 +1,307 @@
651 +/*
652 + * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
653 + * Copyright 2012 SAP AG. All rights reserved.
654 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
655 + *
656 + * This code is free software; you can redistribute it and/or modify it
657 + * under the terms of the GNU General Public License version 2 only, as
658 + * published by the Free Software Foundation.
659 + *
660 + * This code is distributed in the hope that it will be useful, but WITHOUT
661 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
662 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
663 + * version 2 for more details (a copy is included in the LICENSE file that
664 + * accompanied this code).
665 + *
666 + * You should have received a copy of the GNU General Public License version
667 + * 2 along with this work; if not, write to the Free Software Foundation,
668 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
669 + *
670 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
671 + * or visit www.oracle.com if you need additional information or have any
672 + * questions.
673 + *
674 + */
675 +
676 +// This file defines a set of macros which are used by the c++-interpreter
677 +// for updating a method's methodData object.
678 +
679 +
680 +#ifndef SHARE_VM_INTERPRETER_BYTECODEINTERPRETERPROFILING_HPP
681 +#define SHARE_VM_INTERPRETER_BYTECODEINTERPRETERPROFILING_HPP
682 +
683 +
684 +// Global settings /////////////////////////////////////////////////////////////
685 +
686 +
687 +// Enables profiling support
688 +#if defined(COMPILER2) && defined(PPC64)
689 +#define CC_INTERP_PROFILE
690 +#endif
691 +
692 +// Enables assertions for profiling code (also works in product-builds).
693 +// #define CC_INTERP_PROFILE_WITH_ASSERTIONS
694 +
695 +
696 +#ifdef CC_INTERP
697 +
698 +// Empty dummy implementations if profiling code is switched off. //////////////
699 +
700 +#ifndef CC_INTERP_PROFILE
701 +
702 +#define SET_MDX(mdx)
703 +
704 +#define BI_PROFILE_GET_OR_CREATE_METHOD_DATA(exception_handler) \
705 + if (ProfileInterpreter) { \
706 + ShouldNotReachHere(); \
707 + }
708 +
709 +#define BI_PROFILE_ALIGN_TO_CURRENT_BCI()
710 +
711 +#define BI_PROFILE_UPDATE_JUMP()
712 +#define BI_PROFILE_UPDATE_BRANCH(is_taken)
713 +#define BI_PROFILE_UPDATE_RET(bci)
714 +#define BI_PROFILE_SUBTYPECHECK_FAILED(receiver)
715 +#define BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver)
716 +#define BI_PROFILE_UPDATE_INSTANCEOF(null_seen, receiver)
717 +#define BI_PROFILE_UPDATE_CALL()
718 +#define BI_PROFILE_UPDATE_FINALCALL()
719 +#define BI_PROFILE_UPDATE_VIRTUALCALL(receiver)
720 +#define BI_PROFILE_UPDATE_SWITCH(switch_index)
721 +
722 +
723 +#else
724 +
725 +
726 +// Non-dummy implementations ///////////////////////////////////////////////////
727 +
728 +// Accessors for the current method data pointer 'mdx'.
729 +#define MDX() (istate->mdx())
730 +#define SET_MDX(mdx) \
731 + if (TraceProfileInterpreter) { \
732 + /* Let it look like TraceBytecodes' format. */ \
733 + tty->print_cr("[%d] %4d " \
734 + "mdx " PTR_FORMAT "(%d)" \
735 + " " \
736 + " \t-> " PTR_FORMAT "(%d)", \
737 + (int) THREAD->osthread()->thread_id(), \
738 + BCI(), \
739 + MDX(), \
740 + (MDX() == NULL \
741 + ? 0 \
742 + : istate->method()->method_data()->dp_to_di((address)MDX())), \
743 + mdx, \
744 + istate->method()->method_data()->dp_to_di((address)mdx) \
745 + ); \
746 + }; \
747 + istate->set_mdx(mdx);
748 +
749 +
750 +// Dumps the profiling method data for the current method.
751 +#ifdef PRODUCT
752 +#define BI_PROFILE_PRINT_METHOD_DATA()
753 +#else // PRODUCT
754 +#define BI_PROFILE_PRINT_METHOD_DATA() \
755 + { \
756 + ttyLocker ttyl; \
757 + MethodData *md = istate->method()->method_data(); \
758 + tty->cr(); \
759 + tty->print("method data at mdx " PTR_FORMAT "(0) for", \
760 + md->data_layout_at(md->bci_to_di(0))); \
761 + istate->method()->print_short_name(tty); \
762 + tty->cr(); \
763 + if (md != NULL) { \
764 + md->print_data_on(tty); \
765 + address mdx = (address) MDX(); \
766 + if (mdx != NULL) { \
767 + tty->print_cr("current mdx " PTR_FORMAT "(%d)", \
768 + mdx, \
769 + istate->method()->method_data()->dp_to_di(mdx)); \
770 + } \
771 + } else { \
772 + tty->print_cr("no method data"); \
773 + } \
774 + }
775 +#endif // PRODUCT
776 +
777 +
778 +// Gets or creates the profiling method data and initializes mdx.
779 +#define BI_PROFILE_GET_OR_CREATE_METHOD_DATA(exception_handler) \
780 + if (ProfileInterpreter && MDX() == NULL) { \
781 + /* Mdx is not yet initialized for this activation. */ \
782 + MethodData *md = istate->method()->method_data(); \
783 + if (md == NULL) { \
784 + MethodCounters* mcs; \
785 + GET_METHOD_COUNTERS(mcs); \
786 + /* The profiling method data doesn't exist for this method, */ \
787 + /* create it if the counters have overflowed. */ \
788 + if (INVOCATION_COUNT(mcs)->reached_ProfileLimit(BACKEDGE_COUNT(mcs))) { \
789 + /* Must use CALL_VM, because an async exception may be pending. */ \
790 + CALL_VM((InterpreterRuntime::profile_method(THREAD)), \
791 + exception_handler); \
792 + md = istate->method()->method_data(); \
793 + if (md != NULL) { \
794 + if (TraceProfileInterpreter) { \
795 + BI_PROFILE_PRINT_METHOD_DATA(); \
796 + } \
797 + Method *m = istate->method(); \
798 + int bci = m->bci_from(pc); \
799 + jint di = md->bci_to_di(bci); \
800 + SET_MDX(md->data_layout_at(di)); \
801 + } \
802 + } \
803 + } else { \
804 + /* The profiling method data exists, align the method data pointer */ \
805 + /* mdx to the current bytecode index. */ \
806 + if (TraceProfileInterpreter) { \
807 + BI_PROFILE_PRINT_METHOD_DATA(); \
808 + } \
809 + SET_MDX(md->data_layout_at(md->bci_to_di(BCI()))); \
810 + } \
811 + }
812 +
813 +
814 +// Asserts that the current method data pointer mdx corresponds
815 +// to the current bytecode.
816 +#if defined(CC_INTERP_PROFILE_WITH_ASSERTIONS)
817 +#define BI_PROFILE_CHECK_MDX() \
818 + { \
819 + MethodData *md = istate->method()->method_data(); \
820 + address mdx = (address) MDX(); \
821 + address mdx2 = (address) md->data_layout_at(md->bci_to_di(BCI())); \
822 + guarantee(md != NULL, "1"); \
823 + guarantee(mdx != NULL, "2"); \
824 + guarantee(mdx2 != NULL, "3"); \
825 + if (mdx != mdx2) { \
826 + BI_PROFILE_PRINT_METHOD_DATA(); \
827 + fatal3("invalid mdx at bci %d:" \
828 + " was " PTR_FORMAT \
829 + " but expected " PTR_FORMAT, \
830 + BCI(), \
831 + mdx, \
832 + mdx2); \
833 + } \
834 + }
835 +#else
836 +#define BI_PROFILE_CHECK_MDX()
837 +#endif
838 +
839 +
840 +// Aligns the method data pointer mdx to the current bytecode index.
841 +#define BI_PROFILE_ALIGN_TO_CURRENT_BCI() \
842 + if (ProfileInterpreter && MDX() != NULL) { \
843 + MethodData *md = istate->method()->method_data(); \
844 + SET_MDX(md->data_layout_at(md->bci_to_di(BCI()))); \
845 + }
846 +
847 +
848 +// Updates profiling data for a jump.
849 +#define BI_PROFILE_UPDATE_JUMP() \
850 + if (ProfileInterpreter && MDX() != NULL) { \
851 + BI_PROFILE_CHECK_MDX(); \
852 + JumpData::increment_taken_count_no_overflow(MDX()); \
853 + /* Remember last branch taken count. */ \
854 + mdo_last_branch_taken_count = JumpData::taken_count(MDX()); \
855 + SET_MDX(JumpData::advance_taken(MDX())); \
856 + }
857 +
858 +
859 +// Updates profiling data for a taken/not taken branch.
860 +#define BI_PROFILE_UPDATE_BRANCH(is_taken) \
861 + if (ProfileInterpreter && MDX() != NULL) { \
862 + BI_PROFILE_CHECK_MDX(); \
863 + if (is_taken) { \
864 + BranchData::increment_taken_count_no_overflow(MDX()); \
865 + /* Remember last branch taken count. */ \
866 + mdo_last_branch_taken_count = BranchData::taken_count(MDX()); \
867 + SET_MDX(BranchData::advance_taken(MDX())); \
868 + } else { \
869 + BranchData::increment_not_taken_count_no_overflow(MDX()); \
870 + SET_MDX(BranchData::advance_not_taken(MDX())); \
871 + } \
872 + }
873 +
874 +
875 +// Updates profiling data for a ret with given bci.
876 +#define BI_PROFILE_UPDATE_RET(bci) \
877 + if (ProfileInterpreter && MDX() != NULL) { \
878 + BI_PROFILE_CHECK_MDX(); \
879 + MethodData *md = istate->method()->method_data(); \
880 +/* FIXME: there is more to do here than increment and advance(mdx)! */ \
881 + CounterData::increment_count_no_overflow(MDX()); \
882 + SET_MDX(RetData::advance(md, bci)); \
883 + }
884 +
885 +// Decrement counter at checkcast if the subtype check fails (as template
886 +// interpreter does!).
887 +#define BI_PROFILE_SUBTYPECHECK_FAILED(receiver) \
888 + if (ProfileInterpreter && MDX() != NULL) { \
889 + BI_PROFILE_CHECK_MDX(); \
890 + ReceiverTypeData::increment_receiver_count_no_overflow(MDX(), receiver); \
891 + ReceiverTypeData::decrement_count(MDX()); \
892 + }
893 +
894 +// Updates profiling data for a checkcast (was a null seen? which receiver?).
895 +#define BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver) \
896 + if (ProfileInterpreter && MDX() != NULL) { \
897 + BI_PROFILE_CHECK_MDX(); \
898 + if (null_seen) { \
899 + ReceiverTypeData::set_null_seen(MDX()); \
900 + } else { \
901 + /* Template interpreter doesn't increment count. */ \
902 + /* ReceiverTypeData::increment_count_no_overflow(MDX());*/ \
903 + ReceiverTypeData::increment_receiver_count_no_overflow(MDX(), receiver); \
904 + } \
905 + SET_MDX(ReceiverTypeData::advance(MDX())); \
906 + }
907 +
908 +
909 +// Updates profiling data for an instanceof (was a null seen? which receiver?).
910 +#define BI_PROFILE_UPDATE_INSTANCEOF(null_seen, receiver) \
911 + BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver)
912 +
913 +
914 +// Updates profiling data for a call.
915 +#define BI_PROFILE_UPDATE_CALL() \
916 + if (ProfileInterpreter && MDX() != NULL) { \
917 + BI_PROFILE_CHECK_MDX(); \
918 + CounterData::increment_count_no_overflow(MDX()); \
919 + SET_MDX(CounterData::advance(MDX())); \
920 + }
921 +
922 +
923 +// Updates profiling data for a final call.
924 +#define BI_PROFILE_UPDATE_FINALCALL() \
925 + if (ProfileInterpreter && MDX() != NULL) { \
926 + BI_PROFILE_CHECK_MDX(); \
927 + VirtualCallData::increment_count_no_overflow(MDX()); \
928 + SET_MDX(VirtualCallData::advance(MDX())); \
929 + }
930 +
931 +
932 +// Updates profiling data for a virtual call with given receiver Klass.
933 +#define BI_PROFILE_UPDATE_VIRTUALCALL(receiver) \
934 + if (ProfileInterpreter && MDX() != NULL) { \
935 + BI_PROFILE_CHECK_MDX(); \
936 + VirtualCallData::increment_receiver_count_no_overflow(MDX(), receiver); \
937 + SET_MDX(VirtualCallData::advance(MDX())); \
938 + }
939 +
940 +
941 +// Updates profiling data for a switch (tabelswitch or lookupswitch) with
942 +// given taken index (-1 means default case was taken).
943 +#define BI_PROFILE_UPDATE_SWITCH(switch_index) \
944 + if (ProfileInterpreter && MDX() != NULL) { \
945 + BI_PROFILE_CHECK_MDX(); \
946 + MultiBranchData::increment_count_no_overflow(MDX(), switch_index); \
947 + SET_MDX(MultiBranchData::advance(MDX(), switch_index)); \
948 + }
949 +
950 +
951 +// The end /////////////////////////////////////////////////////////////////////
952 +
953 +#endif // CC_INTERP_PROFILE
954 +
955 +#endif // CC_INTERP
956 +
957 +#endif // SHARE_VM_INTERPRETER_BYTECODECINTERPRETERPROFILING_HPP
958 diff -r 84fd980e69ee src/share/vm/interpreter/interpreterRuntime.cpp
959 --- a/src/share/vm/interpreter/interpreterRuntime.cpp Fri Jun 07 12:50:21 2013 +0200
960 +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Fri Jun 07 12:51:22 2013 +0200
961 @@ -267,6 +267,49 @@
962 }
963 }
964
965 +#ifdef CC_INTERP
966 +// As legacy note_trap, but we have more arguments.
967 +IRT_ENTRY(void, InterpreterRuntime::note_trap(JavaThread* thread, int reason, Method *method, int trap_bci))
968 + methodHandle trap_method(method);
969 +
970 + // START derived from note_trap
971 + // passed as arg: methodHandle trap_method(thread, method(thread));
972 + if (trap_method.not_null()) {
973 + MethodData *trap_md = trap_method->method_data();
974 + if (trap_md == NULL) {
975 + Method::build_interpreter_method_data(trap_method, THREAD);
976 + if (HAS_PENDING_EXCEPTION) {
977 + assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
978 + CLEAR_PENDING_EXCEPTION;
979 + }
980 + trap_md = trap_method->method_data();
981 + // and fall through...
982 + }
983 + if (trap_md != NULL) {
984 + // Update per-method count of trap events. The interpreter
985 + // is updating the MDO to simulate the effect of compiler traps.
986 + // Passed as arg int trap_bci = trap_method->bci_from(bcp(thread));
987 + Deoptimization::update_method_data_from_interpreter(trap_md, trap_bci, reason);
988 + }
989 + }
990 + // END derived from note_trap
991 +IRT_END
992 +
993 +// Class Deoptimization is not visible in BytecodeInterpreter, so we need a wrapper
994 +// for each exception.
995 +void InterpreterRuntime::note_nullCheck_trap(JavaThread* thread, Method *method, int trap_bci)
996 + { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_null_check, method, trap_bci); }
997 +void InterpreterRuntime::note_div0Check_trap(JavaThread* thread, Method *method, int trap_bci)
998 + { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_div0_check, method, trap_bci); }
999 +void InterpreterRuntime::note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci)
1000 + { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_range_check, method, trap_bci); }
1001 +void InterpreterRuntime::note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci)
1002 + { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_class_check, method, trap_bci); }
1003 +void InterpreterRuntime::note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci)
1004 + { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_array_check, method, trap_bci); }
1005 +#endif // CC_INTERP
1006 +
1007 +
1008 static Handle get_preinitialized_exception(Klass* k, TRAPS) {
1009 // get klass
1010 InstanceKlass* klass = InstanceKlass::cast(k);
1011 diff -r 84fd980e69ee src/share/vm/interpreter/interpreterRuntime.hpp
1012 --- a/src/share/vm/interpreter/interpreterRuntime.hpp Fri Jun 07 12:50:21 2013 +0200
1013 +++ b/src/share/vm/interpreter/interpreterRuntime.hpp Fri Jun 07 12:51:22 2013 +0200
1014 @@ -67,6 +67,10 @@
1015 static ConstantPoolCacheEntry* cache_entry_at(JavaThread *thread, int i) { return method(thread)->constants()->cache()->entry_at(i); }
1016 static ConstantPoolCacheEntry* cache_entry(JavaThread *thread) { return cache_entry_at(thread, Bytes::get_native_u2(bcp(thread) + 1)); }
1017 static void note_trap(JavaThread *thread, int reason, TRAPS);
1018 +#ifdef CC_INTERP
1019 + // Profile traps in C++ interpreter.
1020 + static void note_trap(JavaThread* thread, int reason, Method *method, int trap_bci);
1021 +#endif // CC_INTERP
1022
1023 // Inner work method for Interpreter's frequency counter overflow
1024 static nmethod* frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp);
1025 @@ -97,6 +101,17 @@
1026 static address exception_handler_for_exception(JavaThread* thread, oopDesc* exception);
1027 static void throw_pending_exception(JavaThread* thread);
1028
1029 +#ifdef CC_INTERP
1030 + // Profile traps in C++ interpreter
1031 + static void note_nullCheck_trap (JavaThread* thread, Method *method, int trap_bci);
1032 + static void note_div0Check_trap (JavaThread* thread, Method *method, int trap_bci);
1033 + static void note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci);
1034 + static void note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci);
1035 + static void note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci);
1036 + // A dummy for makros that shall not profile traps
1037 + static void note_no_trap(JavaThread* thread, Method *method, int trap_bci) {}
1038 +#endif // CC_INTERP
1039 +
1040 // Statics & fields
1041 static void resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode);
1042
1043 diff -r 84fd980e69ee src/share/vm/interpreter/invocationCounter.hpp
1044 --- a/src/share/vm/interpreter/invocationCounter.hpp Fri Jun 07 12:50:21 2013 +0200
1045 +++ b/src/share/vm/interpreter/invocationCounter.hpp Fri Jun 07 12:51:22 2013 +0200
1046 @@ -101,13 +101,17 @@
1047
1048 // Test counter using scaled limits like the asm interpreter would do rather than doing
1049 // the shifts to normalize the counter.
1050 -
1051 - bool reached_InvocationLimit() const { return _counter >= (unsigned int) InterpreterInvocationLimit; }
1052 - bool reached_BackwardBranchLimit() const { return _counter >= (unsigned int) InterpreterBackwardBranchLimit; }
1053 + // Checks sum of invocation_counter and backedge_counter as the template interpreter does.
1054 + bool reached_InvocationLimit(InvocationCounter *back_edge_count) const {
1055 + return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >= (unsigned int) InterpreterInvocationLimit;
1056 + }
1057 + bool reached_BackwardBranchLimit(InvocationCounter *back_edge_count) const {
1058 + return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >= (unsigned int) InterpreterBackwardBranchLimit;
1059 + }
1060
1061 // Do this just like asm interpreter does for max speed
1062 - bool reached_ProfileLimit(InvocationCounter *back_edge_count) const {
1063 - return (_counter && count_mask) + back_edge_count->_counter >= (unsigned int) InterpreterProfileLimit;
1064 + bool reached_ProfileLimit(InvocationCounter *back_edge_count) const {
1065 + return (_counter & count_mask) + (back_edge_count->_counter & count_mask) >= (unsigned int) InterpreterProfileLimit;
1066 }
1067
1068 void increment() { _counter += count_increment; }
1069 diff -r 84fd980e69ee src/share/vm/oops/methodData.cpp
1070 --- a/src/share/vm/oops/methodData.cpp Fri Jun 07 12:50:21 2013 +0200
1071 +++ b/src/share/vm/oops/methodData.cpp Fri Jun 07 12:51:22 2013 +0200
1072 @@ -244,6 +244,11 @@
1073 return mdp;
1074 }
1075
1076 +#ifdef CC_INTERP
1077 +DataLayout* RetData::advance(MethodData *md, int bci) {
1078 + return (DataLayout*) md->bci_to_dp(bci);
1079 +}
1080 +#endif // CC_INTERP
1081
1082 #ifndef PRODUCT
1083 void RetData::print_data_on(outputStream* st) {
1084 diff -r 84fd980e69ee src/share/vm/oops/methodData.hpp
1085 --- a/src/share/vm/oops/methodData.hpp Fri Jun 07 12:50:21 2013 +0200
1086 +++ b/src/share/vm/oops/methodData.hpp Fri Jun 07 12:51:22 2013 +0200
1087 @@ -225,6 +225,11 @@
1088 static ByteSize cell_offset(int index) {
1089 return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size);
1090 }
1091 +#ifdef CC_INTERP
1092 + static int cell_offset_in_bytes(int index) {
1093 + return (int)offset_of(DataLayout, _cells[index]);
1094 + }
1095 +#endif // CC_INTERP
1096 // Return a value which, when or-ed as a byte into _flags, sets the flag.
1097 static int flag_number_to_byte_constant(int flag_number) {
1098 assert(0 <= flag_number && flag_number < flag_limit, "oob");
1099 @@ -356,6 +361,41 @@
1100 _data = data;
1101 }
1102
1103 +#ifdef CC_INTERP
1104 + // Static low level accessors for DataLayout with ProfileData's semantics.
1105 +
1106 + static int cell_offset_in_bytes(int index) {
1107 + return DataLayout::cell_offset_in_bytes(index);
1108 + }
1109 +
1110 + static void increment_uint_at_no_overflow(DataLayout* layout, int index,
1111 + int inc = DataLayout::counter_increment) {
1112 + uint count = ((uint)layout->cell_at(index)) + inc;
1113 + if (count == 0) return;
1114 + layout->set_cell_at(index, (intptr_t) count);
1115 + }
1116 +
1117 + static int int_at(DataLayout* layout, int index) {
1118 + return (int)layout->cell_at(index);
1119 + }
1120 +
1121 + static int uint_at(DataLayout* layout, int index) {
1122 + return (uint)layout->cell_at(index);
1123 + }
1124 +
1125 + static oop oop_at(DataLayout* layout, int index) {
1126 + return (oop)layout->cell_at(index);
1127 + }
1128 +
1129 + static void set_intptr_at(DataLayout* layout, int index, intptr_t value) {
1130 + layout->set_cell_at(index, (intptr_t) value);
1131 + }
1132 +
1133 + static void set_flag_at(DataLayout* layout, int flag_number) {
1134 + layout->set_flag_at(flag_number);
1135 + }
1136 +#endif // CC_INTERP
1137 +
1138 public:
1139 // Constructor for invalid ProfileData.
1140 ProfileData();
1141 @@ -495,6 +535,20 @@
1142 return cell_offset(bit_cell_count);
1143 }
1144
1145 +#ifdef CC_INTERP
1146 + static int bit_data_size_in_bytes() {
1147 + return cell_offset_in_bytes(bit_cell_count);
1148 + }
1149 +
1150 + static void set_null_seen(DataLayout* layout) {
1151 + set_flag_at(layout, null_seen_flag);
1152 + }
1153 +
1154 + static DataLayout* advance(DataLayout* layout) {
1155 + return (DataLayout*) (((address)layout) + (ssize_t)BitData::bit_data_size_in_bytes());
1156 + }
1157 +#endif // CC_INTERP
1158 +
1159 #ifndef PRODUCT
1160 void print_data_on(outputStream* st);
1161 #endif
1162 @@ -539,6 +593,25 @@
1163 set_uint_at(count_off, count);
1164 }
1165
1166 +#ifdef CC_INTERP
1167 + static int counter_data_size_in_bytes() {
1168 + return cell_offset_in_bytes(counter_cell_count);
1169 + }
1170 +
1171 + static void increment_count_no_overflow(DataLayout* layout) {
1172 + increment_uint_at_no_overflow(layout, count_off);
1173 + }
1174 +
1175 + // Support counter decrementation at checkcast / subtype check failed
1176 + static void decrement_count(DataLayout* layout) {
1177 + increment_uint_at_no_overflow(layout, count_off, -1);
1178 + }
1179 +
1180 + static DataLayout* advance(DataLayout* layout) {
1181 + return (DataLayout*) (((address)layout) + (ssize_t)CounterData::counter_data_size_in_bytes());
1182 + }
1183 +#endif // CC_INTERP
1184 +
1185 #ifndef PRODUCT
1186 void print_data_on(outputStream* st);
1187 #endif
1188 @@ -609,6 +682,20 @@
1189 return cell_offset(displacement_off_set);
1190 }
1191
1192 +#ifdef CC_INTERP
1193 + static void increment_taken_count_no_overflow(DataLayout* layout) {
1194 + increment_uint_at_no_overflow(layout, taken_off_set);
1195 + }
1196 +
1197 + static DataLayout* advance_taken(DataLayout* layout) {
1198 + return (DataLayout*) (((address)layout) + (ssize_t)int_at(layout, displacement_off_set));
1199 + }
1200 +
1201 + static uint taken_count(DataLayout* layout) {
1202 + return (uint) uint_at(layout, taken_off_set);
1203 + }
1204 +#endif // CC_INTERP
1205 +
1206 // Specific initialization.
1207 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1208
1209 @@ -718,6 +805,43 @@
1210 // GC support
1211 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
1212
1213 +#ifdef CC_INTERP
1214 + static int receiver_type_data_size_in_bytes() {
1215 + return cell_offset_in_bytes(static_cell_count());
1216 + }
1217 +
1218 + static Klass *receiver_unchecked(DataLayout* layout, uint row) {
1219 + oop recv = oop_at(layout, receiver_cell_index(row));
1220 + return (Klass *)recv;
1221 + }
1222 +
1223 + static void increment_receiver_count_no_overflow(DataLayout* layout, Klass *rcvr) {
1224 + const int num_rows = row_limit();
1225 + // Receiver already exists?
1226 + for (int row = 0; row < num_rows; row++) {
1227 + if (receiver_unchecked(layout, row) == rcvr) {
1228 + increment_uint_at_no_overflow(layout, receiver_count_cell_index(row));
1229 + return;
1230 + }
1231 + }
1232 + // New receiver, find a free slot.
1233 + for (int row = 0; row < num_rows; row++) {
1234 + if (receiver_unchecked(layout, row) == NULL) {
1235 + set_intptr_at(layout, receiver_cell_index(row), (intptr_t)rcvr);
1236 + increment_uint_at_no_overflow(layout, receiver_count_cell_index(row));
1237 + return;
1238 + }
1239 + }
1240 + // Receiver did not match any saved receiver and there is no empty row for it.
1241 + // Increment total counter to indicate polymorphic case.
1242 + increment_count_no_overflow(layout);
1243 + }
1244 +
1245 + static DataLayout* advance(DataLayout* layout) {
1246 + return (DataLayout*) (((address)layout) + (ssize_t)ReceiverTypeData::receiver_type_data_size_in_bytes());
1247 + }
1248 +#endif // CC_INTERP
1249 +
1250 #ifndef PRODUCT
1251 void print_receiver_data_on(outputStream* st);
1252 void print_data_on(outputStream* st);
1253 @@ -751,6 +875,16 @@
1254 return cell_offset(static_cell_count());
1255 }
1256
1257 +#ifdef CC_INTERP
1258 + static int virtual_call_data_size_in_bytes() {
1259 + return cell_offset_in_bytes(static_cell_count());
1260 + }
1261 +
1262 + static DataLayout* advance(DataLayout* layout) {
1263 + return (DataLayout*) (((address)layout) + (ssize_t)VirtualCallData::virtual_call_data_size_in_bytes());
1264 + }
1265 +#endif // CC_INTERP
1266 +
1267 #ifndef PRODUCT
1268 void print_data_on(outputStream* st);
1269 #endif
1270 @@ -847,6 +981,10 @@
1271 return cell_offset(bci_displacement_cell_index(row));
1272 }
1273
1274 +#ifdef CC_INTERP
1275 + static DataLayout* advance(MethodData *md, int bci);
1276 +#endif // CC_INTERP
1277 +
1278 // Specific initialization.
1279 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1280
1281 @@ -911,6 +1049,20 @@
1282 return cell_offset(branch_cell_count);
1283 }
1284
1285 +#ifdef CC_INTERP
1286 + static int branch_data_size_in_bytes() {
1287 + return cell_offset_in_bytes(branch_cell_count);
1288 + }
1289 +
1290 + static void increment_not_taken_count_no_overflow(DataLayout* layout) {
1291 + increment_uint_at_no_overflow(layout, not_taken_off_set);
1292 + }
1293 +
1294 + static DataLayout* advance_not_taken(DataLayout* layout) {
1295 + return (DataLayout*) (((address)layout) + (ssize_t)BranchData::branch_data_size_in_bytes());
1296 + }
1297 +#endif // CC_INTERP
1298 +
1299 // Specific initialization.
1300 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1301
1302 @@ -950,6 +1102,20 @@
1303 set_int_at(aindex, value);
1304 }
1305
1306 +#ifdef CC_INTERP
1307 + // Static low level accessors for DataLayout with ArrayData's semantics.
1308 +
1309 + static void increment_array_uint_at_no_overflow(DataLayout* layout, int index) {
1310 + int aindex = index + array_start_off_set;
1311 + increment_uint_at_no_overflow(layout, aindex);
1312 + }
1313 +
1314 + static int array_int_at(DataLayout* layout, int index) {
1315 + int aindex = index + array_start_off_set;
1316 + return int_at(layout, aindex);
1317 + }
1318 +#endif // CC_INTERP
1319 +
1320 // Code generation support for subclasses.
1321 static ByteSize array_element_offset(int index) {
1322 return cell_offset(array_start_off_set + index);
1323 @@ -1068,6 +1234,28 @@
1324 return in_ByteSize(relative_displacement_off_set) * cell_size;
1325 }
1326
1327 +#ifdef CC_INTERP
1328 + static void increment_count_no_overflow(DataLayout* layout, int index) {
1329 + if (index == -1) {
1330 + increment_array_uint_at_no_overflow(layout, default_count_off_set);
1331 + } else {
1332 + increment_array_uint_at_no_overflow(layout, case_array_start +
1333 + index * per_case_cell_count +
1334 + relative_count_off_set);
1335 + }
1336 + }
1337 +
1338 + static DataLayout* advance(DataLayout* layout, int index) {
1339 + if (index == -1) {
1340 + return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, default_disaplacement_off_set));
1341 + } else {
1342 + return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, case_array_start +
1343 + index * per_case_cell_count +
1344 + relative_displacement_off_set));
1345 + }
1346 + }
1347 +#endif // CC_INTERP
1348 +
1349 // Specific initialization.
1350 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1351
1352 @@ -1146,8 +1334,11 @@
1353 // adjusted in the event of a change in control flow.
1354 //
1355
1356 +CC_INTERP_ONLY(class BytecodeInterpreter;)
1357 +
1358 class MethodData : public Metadata {
1359 friend class VMStructs;
1360 + CC_INTERP_ONLY(friend class BytecodeInterpreter;)
1361 private:
1362 friend class ProfileData;
1363
1364 diff -r 84fd980e69ee src/share/vm/runtime/arguments.cpp
1365 --- a/src/share/vm/runtime/arguments.cpp Fri Jun 07 12:50:21 2013 +0200
1366 +++ b/src/share/vm/runtime/arguments.cpp Fri Jun 07 12:51:22 2013 +0200
1367 @@ -3578,10 +3578,10 @@
1368 // Clear flags not supported by the C++ interpreter
1369 #if !defined(PPC64)
1370 FLAG_SET_DEFAULT(UseBiasedLocking, false);
1371 + FLAG_SET_DEFAULT(ProfileInterpreter, false);
1372 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false));
1373 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedKlassPointers, false));
1374 #endif // !PPC64
1375 - FLAG_SET_DEFAULT(ProfileInterpreter, false);
1376 #endif // CC_INTERP
1377
1378 #ifdef COMPILER2
1379 diff -r 84fd980e69ee src/share/vm/runtime/globals.hpp
1380 --- a/src/share/vm/runtime/globals.hpp Fri Jun 07 12:50:21 2013 +0200
1381 +++ b/src/share/vm/runtime/globals.hpp Fri Jun 07 12:51:22 2013 +0200
1382 @@ -2708,6 +2708,9 @@
1383 product_pd(bool, ProfileInterpreter, \
1384 "Profile at the bytecode level during interpretation") \
1385 \
1386 + develop(bool, TraceProfileInterpreter, false, \
1387 + "Trace profiling at the bytecode level during interpretation") \
1388 + \
1389 develop_pd(bool, ProfileTraps, \
1390 "Profile deoptimization traps at the bytecode level") \
1391 \