Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
32285 views
1
/*
2
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
// no precompiled headers
26
#include "classfile/vmSymbols.hpp"
27
#include "gc_interface/collectedHeap.hpp"
28
#include "interpreter/bytecodeHistogram.hpp"
29
#include "interpreter/bytecodeInterpreter.hpp"
30
#include "interpreter/bytecodeInterpreter.inline.hpp"
31
#include "interpreter/bytecodeInterpreterProfiling.hpp"
32
#include "interpreter/interpreter.hpp"
33
#include "interpreter/interpreterRuntime.hpp"
34
#include "memory/resourceArea.hpp"
35
#include "oops/methodCounters.hpp"
36
#include "oops/objArrayKlass.hpp"
37
#include "oops/oop.inline.hpp"
38
#include "prims/jvmtiExport.hpp"
39
#include "prims/jvmtiThreadState.hpp"
40
#include "runtime/biasedLocking.hpp"
41
#include "runtime/frame.inline.hpp"
42
#include "runtime/handles.inline.hpp"
43
#include "runtime/interfaceSupport.hpp"
44
#include "runtime/orderAccess.inline.hpp"
45
#include "runtime/sharedRuntime.hpp"
46
#include "runtime/threadCritical.hpp"
47
#include "utilities/exceptions.hpp"
48
49
// no precompiled headers
50
#ifdef CC_INTERP
51
52
/*
53
* USELABELS - If using GCC, then use labels for the opcode dispatching
54
* rather -then a switch statement. This improves performance because it
55
* gives us the oportunity to have the instructions that calculate the
56
* next opcode to jump to be intermixed with the rest of the instructions
57
* that implement the opcode (see UPDATE_PC_AND_TOS_AND_CONTINUE macro).
58
*/
59
#undef USELABELS
60
#ifdef __GNUC__
61
/*
62
ASSERT signifies debugging. It is much easier to step thru bytecodes if we
63
don't use the computed goto approach.
64
*/
65
#ifndef ASSERT
66
#define USELABELS
67
#endif
68
#endif
69
70
#undef CASE
71
#ifdef USELABELS
72
#define CASE(opcode) opc ## opcode
73
#define DEFAULT opc_default
74
#else
75
#define CASE(opcode) case Bytecodes:: opcode
76
#define DEFAULT default
77
#endif
78
79
/*
80
* PREFETCH_OPCCODE - Some compilers do better if you prefetch the next
81
* opcode before going back to the top of the while loop, rather then having
82
* the top of the while loop handle it. This provides a better opportunity
83
* for instruction scheduling. Some compilers just do this prefetch
84
* automatically. Some actually end up with worse performance if you
85
* force the prefetch. Solaris gcc seems to do better, but cc does worse.
86
*/
87
#undef PREFETCH_OPCCODE
88
#define PREFETCH_OPCCODE
89
90
/*
91
Interpreter safepoint: it is expected that the interpreter will have no live
92
handles of its own creation live at an interpreter safepoint. Therefore we
93
run a HandleMarkCleaner and trash all handles allocated in the call chain
94
since the JavaCalls::call_helper invocation that initiated the chain.
95
There really shouldn't be any handles remaining to trash but this is cheap
96
in relation to a safepoint.
97
*/
98
#define SAFEPOINT \
99
if ( SafepointSynchronize::is_synchronizing()) { \
100
{ \
101
/* zap freed handles rather than GC'ing them */ \
102
HandleMarkCleaner __hmc(THREAD); \
103
} \
104
CALL_VM(SafepointSynchronize::block(THREAD), handle_exception); \
105
}
106
107
/*
108
* VM_JAVA_ERROR - Macro for throwing a java exception from
109
* the interpreter loop. Should really be a CALL_VM but there
110
* is no entry point to do the transition to vm so we just
111
* do it by hand here.
112
*/
113
#define VM_JAVA_ERROR_NO_JUMP(name, msg, note_a_trap) \
114
DECACHE_STATE(); \
115
SET_LAST_JAVA_FRAME(); \
116
{ \
117
InterpreterRuntime::note_a_trap(THREAD, istate->method(), BCI()); \
118
ThreadInVMfromJava trans(THREAD); \
119
Exceptions::_throw_msg(THREAD, __FILE__, __LINE__, name, msg); \
120
} \
121
RESET_LAST_JAVA_FRAME(); \
122
CACHE_STATE();
123
124
// Normal throw of a java error.
125
#define VM_JAVA_ERROR(name, msg, note_a_trap) \
126
VM_JAVA_ERROR_NO_JUMP(name, msg, note_a_trap) \
127
goto handle_exception;
128
129
#ifdef PRODUCT
130
#define DO_UPDATE_INSTRUCTION_COUNT(opcode)
131
#else
132
#define DO_UPDATE_INSTRUCTION_COUNT(opcode) \
133
{ \
134
BytecodeCounter::_counter_value++; \
135
BytecodeHistogram::_counters[(Bytecodes::Code)opcode]++; \
136
if (StopInterpreterAt && StopInterpreterAt == BytecodeCounter::_counter_value) os::breakpoint(); \
137
if (TraceBytecodes) { \
138
CALL_VM((void)SharedRuntime::trace_bytecode(THREAD, 0, \
139
topOfStack[Interpreter::expr_index_at(1)], \
140
topOfStack[Interpreter::expr_index_at(2)]), \
141
handle_exception); \
142
} \
143
}
144
#endif
145
146
#undef DEBUGGER_SINGLE_STEP_NOTIFY
147
#ifdef VM_JVMTI
148
/* NOTE: (kbr) This macro must be called AFTER the PC has been
149
incremented. JvmtiExport::at_single_stepping_point() may cause a
150
breakpoint opcode to get inserted at the current PC to allow the
151
debugger to coalesce single-step events.
152
153
As a result if we call at_single_stepping_point() we refetch opcode
154
to get the current opcode. This will override any other prefetching
155
that might have occurred.
156
*/
157
#define DEBUGGER_SINGLE_STEP_NOTIFY() \
158
{ \
159
if (_jvmti_interp_events) { \
160
if (JvmtiExport::should_post_single_step()) { \
161
DECACHE_STATE(); \
162
SET_LAST_JAVA_FRAME(); \
163
ThreadInVMfromJava trans(THREAD); \
164
JvmtiExport::at_single_stepping_point(THREAD, \
165
istate->method(), \
166
pc); \
167
RESET_LAST_JAVA_FRAME(); \
168
CACHE_STATE(); \
169
if (THREAD->pop_frame_pending() && \
170
!THREAD->pop_frame_in_process()) { \
171
goto handle_Pop_Frame; \
172
} \
173
if (THREAD->jvmti_thread_state() && \
174
THREAD->jvmti_thread_state()->is_earlyret_pending()) { \
175
goto handle_Early_Return; \
176
} \
177
opcode = *pc; \
178
} \
179
} \
180
}
181
#else
182
#define DEBUGGER_SINGLE_STEP_NOTIFY()
183
#endif
184
185
/*
186
* CONTINUE - Macro for executing the next opcode.
187
*/
188
#undef CONTINUE
189
#ifdef USELABELS
190
// Have to do this dispatch this way in C++ because otherwise gcc complains about crossing an
191
// initialization (which is is the initialization of the table pointer...)
192
#define DISPATCH(opcode) goto *(void*)dispatch_table[opcode]
193
#define CONTINUE { \
194
opcode = *pc; \
195
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
196
DEBUGGER_SINGLE_STEP_NOTIFY(); \
197
DISPATCH(opcode); \
198
}
199
#else
200
#ifdef PREFETCH_OPCCODE
201
#define CONTINUE { \
202
opcode = *pc; \
203
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
204
DEBUGGER_SINGLE_STEP_NOTIFY(); \
205
continue; \
206
}
207
#else
208
#define CONTINUE { \
209
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
210
DEBUGGER_SINGLE_STEP_NOTIFY(); \
211
continue; \
212
}
213
#endif
214
#endif
215
216
217
#define UPDATE_PC(opsize) {pc += opsize; }
218
/*
219
* UPDATE_PC_AND_TOS - Macro for updating the pc and topOfStack.
220
*/
221
#undef UPDATE_PC_AND_TOS
222
#define UPDATE_PC_AND_TOS(opsize, stack) \
223
{pc += opsize; MORE_STACK(stack); }
224
225
/*
226
* UPDATE_PC_AND_TOS_AND_CONTINUE - Macro for updating the pc and topOfStack,
227
* and executing the next opcode. It's somewhat similar to the combination
228
* of UPDATE_PC_AND_TOS and CONTINUE, but with some minor optimizations.
229
*/
230
#undef UPDATE_PC_AND_TOS_AND_CONTINUE
231
#ifdef USELABELS
232
#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \
233
pc += opsize; opcode = *pc; MORE_STACK(stack); \
234
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
235
DEBUGGER_SINGLE_STEP_NOTIFY(); \
236
DISPATCH(opcode); \
237
}
238
239
#define UPDATE_PC_AND_CONTINUE(opsize) { \
240
pc += opsize; opcode = *pc; \
241
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
242
DEBUGGER_SINGLE_STEP_NOTIFY(); \
243
DISPATCH(opcode); \
244
}
245
#else
246
#ifdef PREFETCH_OPCCODE
247
#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \
248
pc += opsize; opcode = *pc; MORE_STACK(stack); \
249
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
250
DEBUGGER_SINGLE_STEP_NOTIFY(); \
251
goto do_continue; \
252
}
253
254
#define UPDATE_PC_AND_CONTINUE(opsize) { \
255
pc += opsize; opcode = *pc; \
256
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
257
DEBUGGER_SINGLE_STEP_NOTIFY(); \
258
goto do_continue; \
259
}
260
#else
261
#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \
262
pc += opsize; MORE_STACK(stack); \
263
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
264
DEBUGGER_SINGLE_STEP_NOTIFY(); \
265
goto do_continue; \
266
}
267
268
#define UPDATE_PC_AND_CONTINUE(opsize) { \
269
pc += opsize; \
270
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
271
DEBUGGER_SINGLE_STEP_NOTIFY(); \
272
goto do_continue; \
273
}
274
#endif /* PREFETCH_OPCCODE */
275
#endif /* USELABELS */
276
277
// About to call a new method, update the save the adjusted pc and return to frame manager
278
#define UPDATE_PC_AND_RETURN(opsize) \
279
DECACHE_TOS(); \
280
istate->set_bcp(pc+opsize); \
281
return;
282
283
284
#define METHOD istate->method()
285
#define GET_METHOD_COUNTERS(res) \
286
res = METHOD->method_counters(); \
287
if (res == NULL) { \
288
CALL_VM(res = InterpreterRuntime::build_method_counters(THREAD, METHOD), handle_exception); \
289
}
290
291
#define OSR_REQUEST(res, branch_pc) \
292
CALL_VM(res=InterpreterRuntime::frequency_counter_overflow(THREAD, branch_pc), handle_exception);
293
/*
294
* For those opcodes that need to have a GC point on a backwards branch
295
*/
296
297
// Backedge counting is kind of strange. The asm interpreter will increment
298
// the backedge counter as a separate counter but it does it's comparisons
299
// to the sum (scaled) of invocation counter and backedge count to make
300
// a decision. Seems kind of odd to sum them together like that
301
302
// skip is delta from current bcp/bci for target, branch_pc is pre-branch bcp
303
304
305
#define DO_BACKEDGE_CHECKS(skip, branch_pc) \
306
if ((skip) <= 0) { \
307
MethodCounters* mcs; \
308
GET_METHOD_COUNTERS(mcs); \
309
if (UseLoopCounter) { \
310
bool do_OSR = UseOnStackReplacement; \
311
mcs->backedge_counter()->increment(); \
312
if (ProfileInterpreter) { \
313
BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception); \
314
/* Check for overflow against MDO count. */ \
315
do_OSR = do_OSR \
316
&& (mdo_last_branch_taken_count >= (uint)InvocationCounter::InterpreterBackwardBranchLimit)\
317
/* When ProfileInterpreter is on, the backedge_count comes */ \
318
/* from the methodDataOop, which value does not get reset on */ \
319
/* the call to frequency_counter_overflow(). To avoid */ \
320
/* excessive calls to the overflow routine while the method is */ \
321
/* being compiled, add a second test to make sure the overflow */ \
322
/* function is called only once every overflow_frequency. */ \
323
&& (!(mdo_last_branch_taken_count & 1023)); \
324
} else { \
325
/* check for overflow of backedge counter */ \
326
do_OSR = do_OSR \
327
&& mcs->invocation_counter()->reached_InvocationLimit(mcs->backedge_counter()); \
328
} \
329
if (do_OSR) { \
330
nmethod* osr_nmethod; \
331
OSR_REQUEST(osr_nmethod, branch_pc); \
332
if (osr_nmethod != NULL && osr_nmethod->osr_entry_bci() != InvalidOSREntryBci) { \
333
intptr_t* buf; \
334
/* Call OSR migration with last java frame only, no checks. */ \
335
CALL_VM_NAKED_LJF(buf=SharedRuntime::OSR_migration_begin(THREAD)); \
336
istate->set_msg(do_osr); \
337
istate->set_osr_buf((address)buf); \
338
istate->set_osr_entry(osr_nmethod->osr_entry()); \
339
return; \
340
} \
341
} \
342
} /* UseCompiler ... */ \
343
SAFEPOINT; \
344
}
345
346
/*
347
* For those opcodes that need to have a GC point on a backwards branch
348
*/
349
350
/*
351
* Macros for caching and flushing the interpreter state. Some local
352
* variables need to be flushed out to the frame before we do certain
353
* things (like pushing frames or becomming gc safe) and some need to
354
* be recached later (like after popping a frame). We could use one
355
* macro to cache or decache everything, but this would be less then
356
* optimal because we don't always need to cache or decache everything
357
* because some things we know are already cached or decached.
358
*/
359
#undef DECACHE_TOS
360
#undef CACHE_TOS
361
#undef CACHE_PREV_TOS
362
#define DECACHE_TOS() istate->set_stack(topOfStack);
363
364
#define CACHE_TOS() topOfStack = (intptr_t *)istate->stack();
365
366
#undef DECACHE_PC
367
#undef CACHE_PC
368
#define DECACHE_PC() istate->set_bcp(pc);
369
#define CACHE_PC() pc = istate->bcp();
370
#define CACHE_CP() cp = istate->constants();
371
#define CACHE_LOCALS() locals = istate->locals();
372
#undef CACHE_FRAME
373
#define CACHE_FRAME()
374
375
// BCI() returns the current bytecode-index.
376
#undef BCI
377
#define BCI() ((int)(intptr_t)(pc - (intptr_t)istate->method()->code_base()))
378
379
/*
380
* CHECK_NULL - Macro for throwing a NullPointerException if the object
381
* passed is a null ref.
382
* On some architectures/platforms it should be possible to do this implicitly
383
*/
384
#undef CHECK_NULL
385
#define CHECK_NULL(obj_) \
386
if ((obj_) == NULL) { \
387
VM_JAVA_ERROR(vmSymbols::java_lang_NullPointerException(), NULL, note_nullCheck_trap); \
388
} \
389
VERIFY_OOP(obj_)
390
391
#define VMdoubleConstZero() 0.0
392
#define VMdoubleConstOne() 1.0
393
#define VMlongConstZero() (max_jlong-max_jlong)
394
#define VMlongConstOne() ((max_jlong-max_jlong)+1)
395
396
/*
397
* Alignment
398
*/
399
#define VMalignWordUp(val) (((uintptr_t)(val) + 3) & ~3)
400
401
// Decache the interpreter state that interpreter modifies directly (i.e. GC is indirect mod)
402
#define DECACHE_STATE() DECACHE_PC(); DECACHE_TOS();
403
404
// Reload interpreter state after calling the VM or a possible GC
405
#define CACHE_STATE() \
406
CACHE_TOS(); \
407
CACHE_PC(); \
408
CACHE_CP(); \
409
CACHE_LOCALS();
410
411
// Call the VM with last java frame only.
412
#define CALL_VM_NAKED_LJF(func) \
413
DECACHE_STATE(); \
414
SET_LAST_JAVA_FRAME(); \
415
func; \
416
RESET_LAST_JAVA_FRAME(); \
417
CACHE_STATE();
418
419
// Call the VM. Don't check for pending exceptions.
420
#define CALL_VM_NOCHECK(func) \
421
CALL_VM_NAKED_LJF(func) \
422
if (THREAD->pop_frame_pending() && \
423
!THREAD->pop_frame_in_process()) { \
424
goto handle_Pop_Frame; \
425
} \
426
if (THREAD->jvmti_thread_state() && \
427
THREAD->jvmti_thread_state()->is_earlyret_pending()) { \
428
goto handle_Early_Return; \
429
}
430
431
// Call the VM and check for pending exceptions
432
#define CALL_VM(func, label) { \
433
CALL_VM_NOCHECK(func); \
434
if (THREAD->has_pending_exception()) goto label; \
435
}
436
437
/*
438
* BytecodeInterpreter::run(interpreterState istate)
439
* BytecodeInterpreter::runWithChecks(interpreterState istate)
440
*
441
* The real deal. This is where byte codes actually get interpreted.
442
* Basically it's a big while loop that iterates until we return from
443
* the method passed in.
444
*
445
* The runWithChecks is used if JVMTI is enabled.
446
*
447
*/
448
#if defined(VM_JVMTI)
449
void
450
BytecodeInterpreter::runWithChecks(interpreterState istate) {
451
#else
452
void
453
BytecodeInterpreter::run(interpreterState istate) {
454
#endif
455
456
// In order to simplify some tests based on switches set at runtime
457
// we invoke the interpreter a single time after switches are enabled
458
// and set simpler to to test variables rather than method calls or complex
459
// boolean expressions.
460
461
static int initialized = 0;
462
static int checkit = 0;
463
static intptr_t* c_addr = NULL;
464
static intptr_t c_value;
465
466
if (checkit && *c_addr != c_value) {
467
os::breakpoint();
468
}
469
#ifdef VM_JVMTI
470
static bool _jvmti_interp_events = 0;
471
#endif
472
473
static int _compiling; // (UseCompiler || CountCompiledCalls)
474
475
#ifdef ASSERT
476
if (istate->_msg != initialize) {
477
// We have a problem here if we are running with a pre-hsx24 JDK (for example during bootstrap)
478
// because in that case, EnableInvokeDynamic is true by default but will be later switched off
479
// if java_lang_invoke_MethodHandle::compute_offsets() detects that the JDK only has the classes
480
// for the old JSR292 implementation.
481
// This leads to a situation where 'istate->_stack_limit' always accounts for
482
// methodOopDesc::extra_stack_entries() because it is computed in
483
// CppInterpreterGenerator::generate_compute_interpreter_state() which was generated while
484
// EnableInvokeDynamic was still true. On the other hand, istate->_method->max_stack() doesn't
485
// account for extra_stack_entries() anymore because at the time when it is called
486
// EnableInvokeDynamic was already set to false.
487
// So we have a second version of the assertion which handles the case where EnableInvokeDynamic was
488
// switched off because of the wrong classes.
489
if (EnableInvokeDynamic || FLAG_IS_CMDLINE(EnableInvokeDynamic)) {
490
assert(labs(istate->_stack_base - istate->_stack_limit) == (istate->_method->max_stack() + 1), "bad stack limit");
491
} else {
492
const int extra_stack_entries = Method::extra_stack_entries_for_jsr292;
493
assert(labs(istate->_stack_base - istate->_stack_limit) == (istate->_method->max_stack() + extra_stack_entries
494
+ 1), "bad stack limit");
495
}
496
#ifndef SHARK
497
IA32_ONLY(assert(istate->_stack_limit == istate->_thread->last_Java_sp() + 1, "wrong"));
498
#endif // !SHARK
499
}
500
// Verify linkages.
501
interpreterState l = istate;
502
do {
503
assert(l == l->_self_link, "bad link");
504
l = l->_prev_link;
505
} while (l != NULL);
506
// Screwups with stack management usually cause us to overwrite istate
507
// save a copy so we can verify it.
508
interpreterState orig = istate;
509
#endif
510
511
register intptr_t* topOfStack = (intptr_t *)istate->stack(); /* access with STACK macros */
512
register address pc = istate->bcp();
513
register jubyte opcode;
514
register intptr_t* locals = istate->locals();
515
register ConstantPoolCache* cp = istate->constants(); // method()->constants()->cache()
516
#ifdef LOTS_OF_REGS
517
register JavaThread* THREAD = istate->thread();
518
#else
519
#undef THREAD
520
#define THREAD istate->thread()
521
#endif
522
523
#ifdef USELABELS
524
const static void* const opclabels_data[256] = {
525
/* 0x00 */ &&opc_nop, &&opc_aconst_null,&&opc_iconst_m1,&&opc_iconst_0,
526
/* 0x04 */ &&opc_iconst_1,&&opc_iconst_2, &&opc_iconst_3, &&opc_iconst_4,
527
/* 0x08 */ &&opc_iconst_5,&&opc_lconst_0, &&opc_lconst_1, &&opc_fconst_0,
528
/* 0x0C */ &&opc_fconst_1,&&opc_fconst_2, &&opc_dconst_0, &&opc_dconst_1,
529
530
/* 0x10 */ &&opc_bipush, &&opc_sipush, &&opc_ldc, &&opc_ldc_w,
531
/* 0x14 */ &&opc_ldc2_w, &&opc_iload, &&opc_lload, &&opc_fload,
532
/* 0x18 */ &&opc_dload, &&opc_aload, &&opc_iload_0,&&opc_iload_1,
533
/* 0x1C */ &&opc_iload_2,&&opc_iload_3,&&opc_lload_0,&&opc_lload_1,
534
535
/* 0x20 */ &&opc_lload_2,&&opc_lload_3,&&opc_fload_0,&&opc_fload_1,
536
/* 0x24 */ &&opc_fload_2,&&opc_fload_3,&&opc_dload_0,&&opc_dload_1,
537
/* 0x28 */ &&opc_dload_2,&&opc_dload_3,&&opc_aload_0,&&opc_aload_1,
538
/* 0x2C */ &&opc_aload_2,&&opc_aload_3,&&opc_iaload, &&opc_laload,
539
540
/* 0x30 */ &&opc_faload, &&opc_daload, &&opc_aaload, &&opc_baload,
541
/* 0x34 */ &&opc_caload, &&opc_saload, &&opc_istore, &&opc_lstore,
542
/* 0x38 */ &&opc_fstore, &&opc_dstore, &&opc_astore, &&opc_istore_0,
543
/* 0x3C */ &&opc_istore_1,&&opc_istore_2,&&opc_istore_3,&&opc_lstore_0,
544
545
/* 0x40 */ &&opc_lstore_1,&&opc_lstore_2,&&opc_lstore_3,&&opc_fstore_0,
546
/* 0x44 */ &&opc_fstore_1,&&opc_fstore_2,&&opc_fstore_3,&&opc_dstore_0,
547
/* 0x48 */ &&opc_dstore_1,&&opc_dstore_2,&&opc_dstore_3,&&opc_astore_0,
548
/* 0x4C */ &&opc_astore_1,&&opc_astore_2,&&opc_astore_3,&&opc_iastore,
549
550
/* 0x50 */ &&opc_lastore,&&opc_fastore,&&opc_dastore,&&opc_aastore,
551
/* 0x54 */ &&opc_bastore,&&opc_castore,&&opc_sastore,&&opc_pop,
552
/* 0x58 */ &&opc_pop2, &&opc_dup, &&opc_dup_x1, &&opc_dup_x2,
553
/* 0x5C */ &&opc_dup2, &&opc_dup2_x1,&&opc_dup2_x2,&&opc_swap,
554
555
/* 0x60 */ &&opc_iadd,&&opc_ladd,&&opc_fadd,&&opc_dadd,
556
/* 0x64 */ &&opc_isub,&&opc_lsub,&&opc_fsub,&&opc_dsub,
557
/* 0x68 */ &&opc_imul,&&opc_lmul,&&opc_fmul,&&opc_dmul,
558
/* 0x6C */ &&opc_idiv,&&opc_ldiv,&&opc_fdiv,&&opc_ddiv,
559
560
/* 0x70 */ &&opc_irem, &&opc_lrem, &&opc_frem,&&opc_drem,
561
/* 0x74 */ &&opc_ineg, &&opc_lneg, &&opc_fneg,&&opc_dneg,
562
/* 0x78 */ &&opc_ishl, &&opc_lshl, &&opc_ishr,&&opc_lshr,
563
/* 0x7C */ &&opc_iushr,&&opc_lushr,&&opc_iand,&&opc_land,
564
565
/* 0x80 */ &&opc_ior, &&opc_lor,&&opc_ixor,&&opc_lxor,
566
/* 0x84 */ &&opc_iinc,&&opc_i2l,&&opc_i2f, &&opc_i2d,
567
/* 0x88 */ &&opc_l2i, &&opc_l2f,&&opc_l2d, &&opc_f2i,
568
/* 0x8C */ &&opc_f2l, &&opc_f2d,&&opc_d2i, &&opc_d2l,
569
570
/* 0x90 */ &&opc_d2f, &&opc_i2b, &&opc_i2c, &&opc_i2s,
571
/* 0x94 */ &&opc_lcmp, &&opc_fcmpl,&&opc_fcmpg,&&opc_dcmpl,
572
/* 0x98 */ &&opc_dcmpg,&&opc_ifeq, &&opc_ifne, &&opc_iflt,
573
/* 0x9C */ &&opc_ifge, &&opc_ifgt, &&opc_ifle, &&opc_if_icmpeq,
574
575
/* 0xA0 */ &&opc_if_icmpne,&&opc_if_icmplt,&&opc_if_icmpge, &&opc_if_icmpgt,
576
/* 0xA4 */ &&opc_if_icmple,&&opc_if_acmpeq,&&opc_if_acmpne, &&opc_goto,
577
/* 0xA8 */ &&opc_jsr, &&opc_ret, &&opc_tableswitch,&&opc_lookupswitch,
578
/* 0xAC */ &&opc_ireturn, &&opc_lreturn, &&opc_freturn, &&opc_dreturn,
579
580
/* 0xB0 */ &&opc_areturn, &&opc_return, &&opc_getstatic, &&opc_putstatic,
581
/* 0xB4 */ &&opc_getfield, &&opc_putfield, &&opc_invokevirtual,&&opc_invokespecial,
582
/* 0xB8 */ &&opc_invokestatic,&&opc_invokeinterface,&&opc_invokedynamic,&&opc_new,
583
/* 0xBC */ &&opc_newarray, &&opc_anewarray, &&opc_arraylength, &&opc_athrow,
584
585
/* 0xC0 */ &&opc_checkcast, &&opc_instanceof, &&opc_monitorenter, &&opc_monitorexit,
586
/* 0xC4 */ &&opc_wide, &&opc_multianewarray, &&opc_ifnull, &&opc_ifnonnull,
587
/* 0xC8 */ &&opc_goto_w, &&opc_jsr_w, &&opc_breakpoint, &&opc_default,
588
/* 0xCC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
589
590
/* 0xD0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
591
/* 0xD4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
592
/* 0xD8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
593
/* 0xDC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
594
595
/* 0xE0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
596
/* 0xE4 */ &&opc_default, &&opc_default, &&opc_fast_aldc, &&opc_fast_aldc_w,
597
/* 0xE8 */ &&opc_return_register_finalizer,
598
&&opc_invokehandle, &&opc_default, &&opc_default,
599
/* 0xEC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
600
601
/* 0xF0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
602
/* 0xF4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
603
/* 0xF8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
604
/* 0xFC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default
605
};
606
register uintptr_t *dispatch_table = (uintptr_t*)&opclabels_data[0];
607
#endif /* USELABELS */
608
609
#ifdef ASSERT
610
// this will trigger a VERIFY_OOP on entry
611
if (istate->msg() != initialize && ! METHOD->is_static()) {
612
oop rcvr = LOCALS_OBJECT(0);
613
VERIFY_OOP(rcvr);
614
}
615
#endif
616
// #define HACK
617
#ifdef HACK
618
bool interesting = false;
619
#endif // HACK
620
621
/* QQQ this should be a stack method so we don't know actual direction */
622
guarantee(istate->msg() == initialize ||
623
topOfStack >= istate->stack_limit() &&
624
topOfStack < istate->stack_base(),
625
"Stack top out of range");
626
627
#ifdef CC_INTERP_PROFILE
628
// MethodData's last branch taken count.
629
uint mdo_last_branch_taken_count = 0;
630
#else
631
const uint mdo_last_branch_taken_count = 0;
632
#endif
633
634
switch (istate->msg()) {
635
case initialize: {
636
if (initialized++) ShouldNotReachHere(); // Only one initialize call.
637
_compiling = (UseCompiler || CountCompiledCalls);
638
#ifdef VM_JVMTI
639
_jvmti_interp_events = JvmtiExport::can_post_interpreter_events();
640
#endif
641
return;
642
}
643
break;
644
case method_entry: {
645
THREAD->set_do_not_unlock();
646
// count invocations
647
assert(initialized, "Interpreter not initialized");
648
if (_compiling) {
649
MethodCounters* mcs;
650
GET_METHOD_COUNTERS(mcs);
651
if (ProfileInterpreter) {
652
METHOD->increment_interpreter_invocation_count(THREAD);
653
}
654
mcs->invocation_counter()->increment();
655
if (mcs->invocation_counter()->reached_InvocationLimit(mcs->backedge_counter())) {
656
CALL_VM((void)InterpreterRuntime::frequency_counter_overflow(THREAD, NULL), handle_exception);
657
// We no longer retry on a counter overflow.
658
}
659
// Get or create profile data. Check for pending (async) exceptions.
660
BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
661
SAFEPOINT;
662
}
663
664
if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) {
665
// initialize
666
os::breakpoint();
667
}
668
669
#ifdef HACK
670
{
671
ResourceMark rm;
672
char *method_name = istate->method()->name_and_sig_as_C_string();
673
if (strstr(method_name, "runThese$TestRunner.run()V") != NULL) {
674
tty->print_cr("entering: depth %d bci: %d",
675
(istate->_stack_base - istate->_stack),
676
istate->_bcp - istate->_method->code_base());
677
interesting = true;
678
}
679
}
680
#endif // HACK
681
682
// Lock method if synchronized.
683
if (METHOD->is_synchronized()) {
684
// oop rcvr = locals[0].j.r;
685
oop rcvr;
686
if (METHOD->is_static()) {
687
rcvr = METHOD->constants()->pool_holder()->java_mirror();
688
} else {
689
rcvr = LOCALS_OBJECT(0);
690
VERIFY_OOP(rcvr);
691
}
692
// The initial monitor is ours for the taking.
693
// Monitor not filled in frame manager any longer as this caused race condition with biased locking.
694
BasicObjectLock* mon = &istate->monitor_base()[-1];
695
mon->set_obj(rcvr);
696
bool success = false;
697
uintptr_t epoch_mask_in_place = (uintptr_t)markOopDesc::epoch_mask_in_place;
698
markOop mark = rcvr->mark();
699
intptr_t hash = (intptr_t) markOopDesc::no_hash;
700
// Implies UseBiasedLocking.
701
if (mark->has_bias_pattern()) {
702
uintptr_t thread_ident;
703
uintptr_t anticipated_bias_locking_value;
704
thread_ident = (uintptr_t)istate->thread();
705
anticipated_bias_locking_value =
706
(((uintptr_t)rcvr->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) &
707
~((uintptr_t) markOopDesc::age_mask_in_place);
708
709
if (anticipated_bias_locking_value == 0) {
710
// Already biased towards this thread, nothing to do.
711
if (PrintBiasedLockingStatistics) {
712
(* BiasedLocking::biased_lock_entry_count_addr())++;
713
}
714
success = true;
715
} else if ((anticipated_bias_locking_value & markOopDesc::biased_lock_mask_in_place) != 0) {
716
// Try to revoke bias.
717
markOop header = rcvr->klass()->prototype_header();
718
if (hash != markOopDesc::no_hash) {
719
header = header->copy_set_hash(hash);
720
}
721
if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), mark) == mark) {
722
if (PrintBiasedLockingStatistics)
723
(*BiasedLocking::revoked_lock_entry_count_addr())++;
724
}
725
} else if ((anticipated_bias_locking_value & epoch_mask_in_place) != 0) {
726
// Try to rebias.
727
markOop new_header = (markOop) ( (intptr_t) rcvr->klass()->prototype_header() | thread_ident);
728
if (hash != markOopDesc::no_hash) {
729
new_header = new_header->copy_set_hash(hash);
730
}
731
if (Atomic::cmpxchg_ptr((void*)new_header, rcvr->mark_addr(), mark) == mark) {
732
if (PrintBiasedLockingStatistics) {
733
(* BiasedLocking::rebiased_lock_entry_count_addr())++;
734
}
735
} else {
736
CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
737
}
738
success = true;
739
} else {
740
// Try to bias towards thread in case object is anonymously biased.
741
markOop header = (markOop) ((uintptr_t) mark &
742
((uintptr_t)markOopDesc::biased_lock_mask_in_place |
743
(uintptr_t)markOopDesc::age_mask_in_place | epoch_mask_in_place));
744
if (hash != markOopDesc::no_hash) {
745
header = header->copy_set_hash(hash);
746
}
747
markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
748
// Debugging hint.
749
DEBUG_ONLY(mon->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
750
if (Atomic::cmpxchg_ptr((void*)new_header, rcvr->mark_addr(), header) == header) {
751
if (PrintBiasedLockingStatistics) {
752
(* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
753
}
754
} else {
755
CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
756
}
757
success = true;
758
}
759
}
760
761
// Traditional lightweight locking.
762
if (!success) {
763
markOop displaced = rcvr->mark()->set_unlocked();
764
mon->lock()->set_displaced_header(displaced);
765
bool call_vm = UseHeavyMonitors;
766
if (call_vm || Atomic::cmpxchg_ptr(mon, rcvr->mark_addr(), displaced) != displaced) {
767
// Is it simple recursive case?
768
if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
769
mon->lock()->set_displaced_header(NULL);
770
} else {
771
CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
772
}
773
}
774
}
775
}
776
THREAD->clr_do_not_unlock();
777
778
// Notify jvmti
779
#ifdef VM_JVMTI
780
if (_jvmti_interp_events) {
781
// Whenever JVMTI puts a thread in interp_only_mode, method
782
// entry/exit events are sent for that thread to track stack depth.
783
if (THREAD->is_interp_only_mode()) {
784
CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
785
handle_exception);
786
}
787
}
788
#endif /* VM_JVMTI */
789
790
goto run;
791
}
792
793
case popping_frame: {
794
// returned from a java call to pop the frame, restart the call
795
// clear the message so we don't confuse ourselves later
796
assert(THREAD->pop_frame_in_process(), "wrong frame pop state");
797
istate->set_msg(no_request);
798
if (_compiling) {
799
// Set MDX back to the ProfileData of the invoke bytecode that will be
800
// restarted.
801
SET_MDX(NULL);
802
BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
803
}
804
THREAD->clr_pop_frame_in_process();
805
goto run;
806
}
807
808
case method_resume: {
809
if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) {
810
// resume
811
os::breakpoint();
812
}
813
#ifdef HACK
814
{
815
ResourceMark rm;
816
char *method_name = istate->method()->name_and_sig_as_C_string();
817
if (strstr(method_name, "runThese$TestRunner.run()V") != NULL) {
818
tty->print_cr("resume: depth %d bci: %d",
819
(istate->_stack_base - istate->_stack) ,
820
istate->_bcp - istate->_method->code_base());
821
interesting = true;
822
}
823
}
824
#endif // HACK
825
// returned from a java call, continue executing.
826
if (THREAD->pop_frame_pending() && !THREAD->pop_frame_in_process()) {
827
goto handle_Pop_Frame;
828
}
829
if (THREAD->jvmti_thread_state() &&
830
THREAD->jvmti_thread_state()->is_earlyret_pending()) {
831
goto handle_Early_Return;
832
}
833
834
if (THREAD->has_pending_exception()) goto handle_exception;
835
// Update the pc by the saved amount of the invoke bytecode size
836
UPDATE_PC(istate->bcp_advance());
837
838
if (_compiling) {
839
// Get or create profile data. Check for pending (async) exceptions.
840
BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
841
}
842
goto run;
843
}
844
845
case deopt_resume2: {
846
// Returned from an opcode that will reexecute. Deopt was
847
// a result of a PopFrame request.
848
//
849
850
if (_compiling) {
851
// Get or create profile data. Check for pending (async) exceptions.
852
BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
853
}
854
goto run;
855
}
856
857
case deopt_resume: {
858
// Returned from an opcode that has completed. The stack has
859
// the result all we need to do is skip across the bytecode
860
// and continue (assuming there is no exception pending)
861
//
862
// compute continuation length
863
//
864
// Note: it is possible to deopt at a return_register_finalizer opcode
865
// because this requires entering the vm to do the registering. While the
866
// opcode is complete we can't advance because there are no more opcodes
867
// much like trying to deopt at a poll return. In that has we simply
868
// get out of here
869
//
870
if ( Bytecodes::code_at(METHOD, pc) == Bytecodes::_return_register_finalizer) {
871
// this will do the right thing even if an exception is pending.
872
goto handle_return;
873
}
874
UPDATE_PC(Bytecodes::length_at(METHOD, pc));
875
if (THREAD->has_pending_exception()) goto handle_exception;
876
877
if (_compiling) {
878
// Get or create profile data. Check for pending (async) exceptions.
879
BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
880
}
881
goto run;
882
}
883
case got_monitors: {
884
// continue locking now that we have a monitor to use
885
// we expect to find newly allocated monitor at the "top" of the monitor stack.
886
oop lockee = STACK_OBJECT(-1);
887
VERIFY_OOP(lockee);
888
// derefing's lockee ought to provoke implicit null check
889
// find a free monitor
890
BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
891
assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");
892
entry->set_obj(lockee);
893
bool success = false;
894
uintptr_t epoch_mask_in_place = (uintptr_t)markOopDesc::epoch_mask_in_place;
895
896
markOop mark = lockee->mark();
897
intptr_t hash = (intptr_t) markOopDesc::no_hash;
898
// implies UseBiasedLocking
899
if (mark->has_bias_pattern()) {
900
uintptr_t thread_ident;
901
uintptr_t anticipated_bias_locking_value;
902
thread_ident = (uintptr_t)istate->thread();
903
anticipated_bias_locking_value =
904
(((uintptr_t)lockee->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) &
905
~((uintptr_t) markOopDesc::age_mask_in_place);
906
907
if (anticipated_bias_locking_value == 0) {
908
// already biased towards this thread, nothing to do
909
if (PrintBiasedLockingStatistics) {
910
(* BiasedLocking::biased_lock_entry_count_addr())++;
911
}
912
success = true;
913
} else if ((anticipated_bias_locking_value & markOopDesc::biased_lock_mask_in_place) != 0) {
914
// try revoke bias
915
markOop header = lockee->klass()->prototype_header();
916
if (hash != markOopDesc::no_hash) {
917
header = header->copy_set_hash(hash);
918
}
919
if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), mark) == mark) {
920
if (PrintBiasedLockingStatistics) {
921
(*BiasedLocking::revoked_lock_entry_count_addr())++;
922
}
923
}
924
} else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
925
// try rebias
926
markOop new_header = (markOop) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident);
927
if (hash != markOopDesc::no_hash) {
928
new_header = new_header->copy_set_hash(hash);
929
}
930
if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), mark) == mark) {
931
if (PrintBiasedLockingStatistics) {
932
(* BiasedLocking::rebiased_lock_entry_count_addr())++;
933
}
934
} else {
935
CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
936
}
937
success = true;
938
} else {
939
// try to bias towards thread in case object is anonymously biased
940
markOop header = (markOop) ((uintptr_t) mark & ((uintptr_t)markOopDesc::biased_lock_mask_in_place |
941
(uintptr_t)markOopDesc::age_mask_in_place | epoch_mask_in_place));
942
if (hash != markOopDesc::no_hash) {
943
header = header->copy_set_hash(hash);
944
}
945
markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
946
// debugging hint
947
DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
948
if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), header) == header) {
949
if (PrintBiasedLockingStatistics) {
950
(* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
951
}
952
} else {
953
CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
954
}
955
success = true;
956
}
957
}
958
959
// traditional lightweight locking
960
if (!success) {
961
markOop displaced = lockee->mark()->set_unlocked();
962
entry->lock()->set_displaced_header(displaced);
963
bool call_vm = UseHeavyMonitors;
964
if (call_vm || Atomic::cmpxchg_ptr(entry, lockee->mark_addr(), displaced) != displaced) {
965
// Is it simple recursive case?
966
if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
967
entry->lock()->set_displaced_header(NULL);
968
} else {
969
CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
970
}
971
}
972
}
973
UPDATE_PC_AND_TOS(1, -1);
974
goto run;
975
}
976
default: {
977
fatal("Unexpected message from frame manager");
978
}
979
}
980
981
run:
982
983
DO_UPDATE_INSTRUCTION_COUNT(*pc)
984
DEBUGGER_SINGLE_STEP_NOTIFY();
985
#ifdef PREFETCH_OPCCODE
986
opcode = *pc; /* prefetch first opcode */
987
#endif
988
989
#ifndef USELABELS
990
while (1)
991
#endif
992
{
993
#ifndef PREFETCH_OPCCODE
994
opcode = *pc;
995
#endif
996
// Seems like this happens twice per opcode. At worst this is only
997
// need at entry to the loop.
998
// DEBUGGER_SINGLE_STEP_NOTIFY();
999
/* Using this labels avoids double breakpoints when quickening and
1000
* when returing from transition frames.
1001
*/
1002
opcode_switch:
1003
assert(istate == orig, "Corrupted istate");
1004
/* QQQ Hmm this has knowledge of direction, ought to be a stack method */
1005
assert(topOfStack >= istate->stack_limit(), "Stack overrun");
1006
assert(topOfStack < istate->stack_base(), "Stack underrun");
1007
1008
#ifdef USELABELS
1009
DISPATCH(opcode);
1010
#else
1011
switch (opcode)
1012
#endif
1013
{
1014
CASE(_nop):
1015
UPDATE_PC_AND_CONTINUE(1);
1016
1017
/* Push miscellaneous constants onto the stack. */
1018
1019
CASE(_aconst_null):
1020
SET_STACK_OBJECT(NULL, 0);
1021
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1022
1023
#undef OPC_CONST_n
1024
#define OPC_CONST_n(opcode, const_type, value) \
1025
CASE(opcode): \
1026
SET_STACK_ ## const_type(value, 0); \
1027
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1028
1029
OPC_CONST_n(_iconst_m1, INT, -1);
1030
OPC_CONST_n(_iconst_0, INT, 0);
1031
OPC_CONST_n(_iconst_1, INT, 1);
1032
OPC_CONST_n(_iconst_2, INT, 2);
1033
OPC_CONST_n(_iconst_3, INT, 3);
1034
OPC_CONST_n(_iconst_4, INT, 4);
1035
OPC_CONST_n(_iconst_5, INT, 5);
1036
OPC_CONST_n(_fconst_0, FLOAT, 0.0);
1037
OPC_CONST_n(_fconst_1, FLOAT, 1.0);
1038
OPC_CONST_n(_fconst_2, FLOAT, 2.0);
1039
1040
#undef OPC_CONST2_n
1041
#define OPC_CONST2_n(opcname, value, key, kind) \
1042
CASE(_##opcname): \
1043
{ \
1044
SET_STACK_ ## kind(VM##key##Const##value(), 1); \
1045
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); \
1046
}
1047
OPC_CONST2_n(dconst_0, Zero, double, DOUBLE);
1048
OPC_CONST2_n(dconst_1, One, double, DOUBLE);
1049
OPC_CONST2_n(lconst_0, Zero, long, LONG);
1050
OPC_CONST2_n(lconst_1, One, long, LONG);
1051
1052
/* Load constant from constant pool: */
1053
1054
/* Push a 1-byte signed integer value onto the stack. */
1055
CASE(_bipush):
1056
SET_STACK_INT((jbyte)(pc[1]), 0);
1057
UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
1058
1059
/* Push a 2-byte signed integer constant onto the stack. */
1060
CASE(_sipush):
1061
SET_STACK_INT((int16_t)Bytes::get_Java_u2(pc + 1), 0);
1062
UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
1063
1064
/* load from local variable */
1065
1066
CASE(_aload):
1067
VERIFY_OOP(LOCALS_OBJECT(pc[1]));
1068
SET_STACK_OBJECT(LOCALS_OBJECT(pc[1]), 0);
1069
UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
1070
1071
CASE(_iload):
1072
CASE(_fload):
1073
SET_STACK_SLOT(LOCALS_SLOT(pc[1]), 0);
1074
UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
1075
1076
CASE(_lload):
1077
SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(pc[1]), 1);
1078
UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);
1079
1080
CASE(_dload):
1081
SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(pc[1]), 1);
1082
UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);
1083
1084
#undef OPC_LOAD_n
1085
#define OPC_LOAD_n(num) \
1086
CASE(_aload_##num): \
1087
VERIFY_OOP(LOCALS_OBJECT(num)); \
1088
SET_STACK_OBJECT(LOCALS_OBJECT(num), 0); \
1089
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); \
1090
\
1091
CASE(_iload_##num): \
1092
CASE(_fload_##num): \
1093
SET_STACK_SLOT(LOCALS_SLOT(num), 0); \
1094
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); \
1095
\
1096
CASE(_lload_##num): \
1097
SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(num), 1); \
1098
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); \
1099
CASE(_dload_##num): \
1100
SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(num), 1); \
1101
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1102
1103
OPC_LOAD_n(0);
1104
OPC_LOAD_n(1);
1105
OPC_LOAD_n(2);
1106
OPC_LOAD_n(3);
1107
1108
/* store to a local variable */
1109
1110
CASE(_astore):
1111
astore(topOfStack, -1, locals, pc[1]);
1112
UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);
1113
1114
CASE(_istore):
1115
CASE(_fstore):
1116
SET_LOCALS_SLOT(STACK_SLOT(-1), pc[1]);
1117
UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);
1118
1119
CASE(_lstore):
1120
SET_LOCALS_LONG(STACK_LONG(-1), pc[1]);
1121
UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);
1122
1123
CASE(_dstore):
1124
SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), pc[1]);
1125
UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);
1126
1127
CASE(_wide): {
1128
uint16_t reg = Bytes::get_Java_u2(pc + 2);
1129
1130
opcode = pc[1];
1131
1132
// Wide and it's sub-bytecode are counted as separate instructions. If we
1133
// don't account for this here, the bytecode trace skips the next bytecode.
1134
DO_UPDATE_INSTRUCTION_COUNT(opcode);
1135
1136
switch(opcode) {
1137
case Bytecodes::_aload:
1138
VERIFY_OOP(LOCALS_OBJECT(reg));
1139
SET_STACK_OBJECT(LOCALS_OBJECT(reg), 0);
1140
UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
1141
1142
case Bytecodes::_iload:
1143
case Bytecodes::_fload:
1144
SET_STACK_SLOT(LOCALS_SLOT(reg), 0);
1145
UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
1146
1147
case Bytecodes::_lload:
1148
SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(reg), 1);
1149
UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);
1150
1151
case Bytecodes::_dload:
1152
SET_STACK_DOUBLE_FROM_ADDR(LOCALS_LONG_AT(reg), 1);
1153
UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);
1154
1155
case Bytecodes::_astore:
1156
astore(topOfStack, -1, locals, reg);
1157
UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);
1158
1159
case Bytecodes::_istore:
1160
case Bytecodes::_fstore:
1161
SET_LOCALS_SLOT(STACK_SLOT(-1), reg);
1162
UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);
1163
1164
case Bytecodes::_lstore:
1165
SET_LOCALS_LONG(STACK_LONG(-1), reg);
1166
UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);
1167
1168
case Bytecodes::_dstore:
1169
SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), reg);
1170
UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);
1171
1172
case Bytecodes::_iinc: {
1173
int16_t offset = (int16_t)Bytes::get_Java_u2(pc+4);
1174
// Be nice to see what this generates.... QQQ
1175
SET_LOCALS_INT(LOCALS_INT(reg) + offset, reg);
1176
UPDATE_PC_AND_CONTINUE(6);
1177
}
1178
case Bytecodes::_ret:
1179
// Profile ret.
1180
BI_PROFILE_UPDATE_RET(/*bci=*/((int)(intptr_t)(LOCALS_ADDR(reg))));
1181
// Now, update the pc.
1182
pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(reg));
1183
UPDATE_PC_AND_CONTINUE(0);
1184
default:
1185
VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode", note_no_trap);
1186
}
1187
}
1188
1189
1190
#undef OPC_STORE_n
1191
#define OPC_STORE_n(num) \
1192
CASE(_astore_##num): \
1193
astore(topOfStack, -1, locals, num); \
1194
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
1195
CASE(_istore_##num): \
1196
CASE(_fstore_##num): \
1197
SET_LOCALS_SLOT(STACK_SLOT(-1), num); \
1198
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1199
1200
OPC_STORE_n(0);
1201
OPC_STORE_n(1);
1202
OPC_STORE_n(2);
1203
OPC_STORE_n(3);
1204
1205
#undef OPC_DSTORE_n
1206
#define OPC_DSTORE_n(num) \
1207
CASE(_dstore_##num): \
1208
SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), num); \
1209
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \
1210
CASE(_lstore_##num): \
1211
SET_LOCALS_LONG(STACK_LONG(-1), num); \
1212
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);
1213
1214
OPC_DSTORE_n(0);
1215
OPC_DSTORE_n(1);
1216
OPC_DSTORE_n(2);
1217
OPC_DSTORE_n(3);
1218
1219
/* stack pop, dup, and insert opcodes */
1220
1221
1222
CASE(_pop): /* Discard the top item on the stack */
1223
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1224
1225
1226
CASE(_pop2): /* Discard the top 2 items on the stack */
1227
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);
1228
1229
1230
CASE(_dup): /* Duplicate the top item on the stack */
1231
dup(topOfStack);
1232
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1233
1234
CASE(_dup2): /* Duplicate the top 2 items on the stack */
1235
dup2(topOfStack);
1236
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1237
1238
CASE(_dup_x1): /* insert top word two down */
1239
dup_x1(topOfStack);
1240
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1241
1242
CASE(_dup_x2): /* insert top word three down */
1243
dup_x2(topOfStack);
1244
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1245
1246
CASE(_dup2_x1): /* insert top 2 slots three down */
1247
dup2_x1(topOfStack);
1248
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1249
1250
CASE(_dup2_x2): /* insert top 2 slots four down */
1251
dup2_x2(topOfStack);
1252
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1253
1254
CASE(_swap): { /* swap top two elements on the stack */
1255
swap(topOfStack);
1256
UPDATE_PC_AND_CONTINUE(1);
1257
}
1258
1259
/* Perform various binary integer operations */
1260
1261
#undef OPC_INT_BINARY
1262
#define OPC_INT_BINARY(opcname, opname, test) \
1263
CASE(_i##opcname): \
1264
if (test && (STACK_INT(-1) == 0)) { \
1265
VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
1266
"/ by zero", note_div0Check_trap); \
1267
} \
1268
SET_STACK_INT(VMint##opname(STACK_INT(-2), \
1269
STACK_INT(-1)), \
1270
-2); \
1271
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
1272
CASE(_l##opcname): \
1273
{ \
1274
if (test) { \
1275
jlong l1 = STACK_LONG(-1); \
1276
if (VMlongEqz(l1)) { \
1277
VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
1278
"/ by long zero", note_div0Check_trap); \
1279
} \
1280
} \
1281
/* First long at (-1,-2) next long at (-3,-4) */ \
1282
SET_STACK_LONG(VMlong##opname(STACK_LONG(-3), \
1283
STACK_LONG(-1)), \
1284
-3); \
1285
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \
1286
}
1287
1288
OPC_INT_BINARY(add, Add, 0);
1289
OPC_INT_BINARY(sub, Sub, 0);
1290
OPC_INT_BINARY(mul, Mul, 0);
1291
OPC_INT_BINARY(and, And, 0);
1292
OPC_INT_BINARY(or, Or, 0);
1293
OPC_INT_BINARY(xor, Xor, 0);
1294
OPC_INT_BINARY(div, Div, 1);
1295
OPC_INT_BINARY(rem, Rem, 1);
1296
1297
1298
/* Perform various binary floating number operations */
1299
/* On some machine/platforms/compilers div zero check can be implicit */
1300
1301
#undef OPC_FLOAT_BINARY
1302
#define OPC_FLOAT_BINARY(opcname, opname) \
1303
CASE(_d##opcname): { \
1304
SET_STACK_DOUBLE(VMdouble##opname(STACK_DOUBLE(-3), \
1305
STACK_DOUBLE(-1)), \
1306
-3); \
1307
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \
1308
} \
1309
CASE(_f##opcname): \
1310
SET_STACK_FLOAT(VMfloat##opname(STACK_FLOAT(-2), \
1311
STACK_FLOAT(-1)), \
1312
-2); \
1313
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1314
1315
1316
OPC_FLOAT_BINARY(add, Add);
1317
OPC_FLOAT_BINARY(sub, Sub);
1318
OPC_FLOAT_BINARY(mul, Mul);
1319
OPC_FLOAT_BINARY(div, Div);
1320
OPC_FLOAT_BINARY(rem, Rem);
1321
1322
/* Shift operations
1323
* Shift left int and long: ishl, lshl
1324
* Logical shift right int and long w/zero extension: iushr, lushr
1325
* Arithmetic shift right int and long w/sign extension: ishr, lshr
1326
*/
1327
1328
#undef OPC_SHIFT_BINARY
1329
#define OPC_SHIFT_BINARY(opcname, opname) \
1330
CASE(_i##opcname): \
1331
SET_STACK_INT(VMint##opname(STACK_INT(-2), \
1332
STACK_INT(-1)), \
1333
-2); \
1334
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
1335
CASE(_l##opcname): \
1336
{ \
1337
SET_STACK_LONG(VMlong##opname(STACK_LONG(-2), \
1338
STACK_INT(-1)), \
1339
-2); \
1340
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
1341
}
1342
1343
OPC_SHIFT_BINARY(shl, Shl);
1344
OPC_SHIFT_BINARY(shr, Shr);
1345
OPC_SHIFT_BINARY(ushr, Ushr);
1346
1347
/* Increment local variable by constant */
1348
CASE(_iinc):
1349
{
1350
// locals[pc[1]].j.i += (jbyte)(pc[2]);
1351
SET_LOCALS_INT(LOCALS_INT(pc[1]) + (jbyte)(pc[2]), pc[1]);
1352
UPDATE_PC_AND_CONTINUE(3);
1353
}
1354
1355
/* negate the value on the top of the stack */
1356
1357
CASE(_ineg):
1358
SET_STACK_INT(VMintNeg(STACK_INT(-1)), -1);
1359
UPDATE_PC_AND_CONTINUE(1);
1360
1361
CASE(_fneg):
1362
SET_STACK_FLOAT(VMfloatNeg(STACK_FLOAT(-1)), -1);
1363
UPDATE_PC_AND_CONTINUE(1);
1364
1365
CASE(_lneg):
1366
{
1367
SET_STACK_LONG(VMlongNeg(STACK_LONG(-1)), -1);
1368
UPDATE_PC_AND_CONTINUE(1);
1369
}
1370
1371
CASE(_dneg):
1372
{
1373
SET_STACK_DOUBLE(VMdoubleNeg(STACK_DOUBLE(-1)), -1);
1374
UPDATE_PC_AND_CONTINUE(1);
1375
}
1376
1377
/* Conversion operations */
1378
1379
CASE(_i2f): /* convert top of stack int to float */
1380
SET_STACK_FLOAT(VMint2Float(STACK_INT(-1)), -1);
1381
UPDATE_PC_AND_CONTINUE(1);
1382
1383
CASE(_i2l): /* convert top of stack int to long */
1384
{
1385
// this is ugly QQQ
1386
jlong r = VMint2Long(STACK_INT(-1));
1387
MORE_STACK(-1); // Pop
1388
SET_STACK_LONG(r, 1);
1389
1390
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1391
}
1392
1393
CASE(_i2d): /* convert top of stack int to double */
1394
{
1395
// this is ugly QQQ (why cast to jlong?? )
1396
jdouble r = (jlong)STACK_INT(-1);
1397
MORE_STACK(-1); // Pop
1398
SET_STACK_DOUBLE(r, 1);
1399
1400
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1401
}
1402
1403
CASE(_l2i): /* convert top of stack long to int */
1404
{
1405
jint r = VMlong2Int(STACK_LONG(-1));
1406
MORE_STACK(-2); // Pop
1407
SET_STACK_INT(r, 0);
1408
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1409
}
1410
1411
CASE(_l2f): /* convert top of stack long to float */
1412
{
1413
jlong r = STACK_LONG(-1);
1414
MORE_STACK(-2); // Pop
1415
SET_STACK_FLOAT(VMlong2Float(r), 0);
1416
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1417
}
1418
1419
CASE(_l2d): /* convert top of stack long to double */
1420
{
1421
jlong r = STACK_LONG(-1);
1422
MORE_STACK(-2); // Pop
1423
SET_STACK_DOUBLE(VMlong2Double(r), 1);
1424
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1425
}
1426
1427
CASE(_f2i): /* Convert top of stack float to int */
1428
SET_STACK_INT(SharedRuntime::f2i(STACK_FLOAT(-1)), -1);
1429
UPDATE_PC_AND_CONTINUE(1);
1430
1431
CASE(_f2l): /* convert top of stack float to long */
1432
{
1433
jlong r = SharedRuntime::f2l(STACK_FLOAT(-1));
1434
MORE_STACK(-1); // POP
1435
SET_STACK_LONG(r, 1);
1436
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1437
}
1438
1439
CASE(_f2d): /* convert top of stack float to double */
1440
{
1441
jfloat f;
1442
jdouble r;
1443
f = STACK_FLOAT(-1);
1444
r = (jdouble) f;
1445
MORE_STACK(-1); // POP
1446
SET_STACK_DOUBLE(r, 1);
1447
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1448
}
1449
1450
CASE(_d2i): /* convert top of stack double to int */
1451
{
1452
jint r1 = SharedRuntime::d2i(STACK_DOUBLE(-1));
1453
MORE_STACK(-2);
1454
SET_STACK_INT(r1, 0);
1455
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1456
}
1457
1458
CASE(_d2f): /* convert top of stack double to float */
1459
{
1460
jfloat r1 = VMdouble2Float(STACK_DOUBLE(-1));
1461
MORE_STACK(-2);
1462
SET_STACK_FLOAT(r1, 0);
1463
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1464
}
1465
1466
CASE(_d2l): /* convert top of stack double to long */
1467
{
1468
jlong r1 = SharedRuntime::d2l(STACK_DOUBLE(-1));
1469
MORE_STACK(-2);
1470
SET_STACK_LONG(r1, 1);
1471
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1472
}
1473
1474
CASE(_i2b):
1475
SET_STACK_INT(VMint2Byte(STACK_INT(-1)), -1);
1476
UPDATE_PC_AND_CONTINUE(1);
1477
1478
CASE(_i2c):
1479
SET_STACK_INT(VMint2Char(STACK_INT(-1)), -1);
1480
UPDATE_PC_AND_CONTINUE(1);
1481
1482
CASE(_i2s):
1483
SET_STACK_INT(VMint2Short(STACK_INT(-1)), -1);
1484
UPDATE_PC_AND_CONTINUE(1);
1485
1486
/* comparison operators */
1487
1488
1489
#define COMPARISON_OP(name, comparison) \
1490
CASE(_if_icmp##name): { \
1491
const bool cmp = (STACK_INT(-2) comparison STACK_INT(-1)); \
1492
int skip = cmp \
1493
? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
1494
address branch_pc = pc; \
1495
/* Profile branch. */ \
1496
BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \
1497
UPDATE_PC_AND_TOS(skip, -2); \
1498
DO_BACKEDGE_CHECKS(skip, branch_pc); \
1499
CONTINUE; \
1500
} \
1501
CASE(_if##name): { \
1502
const bool cmp = (STACK_INT(-1) comparison 0); \
1503
int skip = cmp \
1504
? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
1505
address branch_pc = pc; \
1506
/* Profile branch. */ \
1507
BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \
1508
UPDATE_PC_AND_TOS(skip, -1); \
1509
DO_BACKEDGE_CHECKS(skip, branch_pc); \
1510
CONTINUE; \
1511
}
1512
1513
#define COMPARISON_OP2(name, comparison) \
1514
COMPARISON_OP(name, comparison) \
1515
CASE(_if_acmp##name): { \
1516
const bool cmp = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1)); \
1517
int skip = cmp \
1518
? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
1519
address branch_pc = pc; \
1520
/* Profile branch. */ \
1521
BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \
1522
UPDATE_PC_AND_TOS(skip, -2); \
1523
DO_BACKEDGE_CHECKS(skip, branch_pc); \
1524
CONTINUE; \
1525
}
1526
1527
#define NULL_COMPARISON_NOT_OP(name) \
1528
CASE(_if##name): { \
1529
const bool cmp = (!(STACK_OBJECT(-1) == NULL)); \
1530
int skip = cmp \
1531
? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
1532
address branch_pc = pc; \
1533
/* Profile branch. */ \
1534
BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \
1535
UPDATE_PC_AND_TOS(skip, -1); \
1536
DO_BACKEDGE_CHECKS(skip, branch_pc); \
1537
CONTINUE; \
1538
}
1539
1540
#define NULL_COMPARISON_OP(name) \
1541
CASE(_if##name): { \
1542
const bool cmp = ((STACK_OBJECT(-1) == NULL)); \
1543
int skip = cmp \
1544
? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
1545
address branch_pc = pc; \
1546
/* Profile branch. */ \
1547
BI_PROFILE_UPDATE_BRANCH(/*is_taken=*/cmp); \
1548
UPDATE_PC_AND_TOS(skip, -1); \
1549
DO_BACKEDGE_CHECKS(skip, branch_pc); \
1550
CONTINUE; \
1551
}
1552
COMPARISON_OP(lt, <);
1553
COMPARISON_OP(gt, >);
1554
COMPARISON_OP(le, <=);
1555
COMPARISON_OP(ge, >=);
1556
COMPARISON_OP2(eq, ==); /* include ref comparison */
1557
COMPARISON_OP2(ne, !=); /* include ref comparison */
1558
NULL_COMPARISON_OP(null);
1559
NULL_COMPARISON_NOT_OP(nonnull);
1560
1561
/* Goto pc at specified offset in switch table. */
1562
1563
CASE(_tableswitch): {
1564
jint* lpc = (jint*)VMalignWordUp(pc+1);
1565
int32_t key = STACK_INT(-1);
1566
int32_t low = Bytes::get_Java_u4((address)&lpc[1]);
1567
int32_t high = Bytes::get_Java_u4((address)&lpc[2]);
1568
int32_t skip;
1569
key -= low;
1570
if (((uint32_t) key > (uint32_t)(high - low))) {
1571
key = -1;
1572
skip = Bytes::get_Java_u4((address)&lpc[0]);
1573
} else {
1574
skip = Bytes::get_Java_u4((address)&lpc[key + 3]);
1575
}
1576
// Profile switch.
1577
BI_PROFILE_UPDATE_SWITCH(/*switch_index=*/key);
1578
// Does this really need a full backedge check (osr)?
1579
address branch_pc = pc;
1580
UPDATE_PC_AND_TOS(skip, -1);
1581
DO_BACKEDGE_CHECKS(skip, branch_pc);
1582
CONTINUE;
1583
}
1584
1585
/* Goto pc whose table entry matches specified key. */
1586
1587
CASE(_lookupswitch): {
1588
jint* lpc = (jint*)VMalignWordUp(pc+1);
1589
int32_t key = STACK_INT(-1);
1590
int32_t skip = Bytes::get_Java_u4((address) lpc); /* default amount */
1591
// Remember index.
1592
int index = -1;
1593
int newindex = 0;
1594
int32_t npairs = Bytes::get_Java_u4((address) &lpc[1]);
1595
while (--npairs >= 0) {
1596
lpc += 2;
1597
if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) {
1598
skip = Bytes::get_Java_u4((address)&lpc[1]);
1599
index = newindex;
1600
break;
1601
}
1602
newindex += 1;
1603
}
1604
// Profile switch.
1605
BI_PROFILE_UPDATE_SWITCH(/*switch_index=*/index);
1606
address branch_pc = pc;
1607
UPDATE_PC_AND_TOS(skip, -1);
1608
DO_BACKEDGE_CHECKS(skip, branch_pc);
1609
CONTINUE;
1610
}
1611
1612
CASE(_fcmpl):
1613
CASE(_fcmpg):
1614
{
1615
SET_STACK_INT(VMfloatCompare(STACK_FLOAT(-2),
1616
STACK_FLOAT(-1),
1617
(opcode == Bytecodes::_fcmpl ? -1 : 1)),
1618
-2);
1619
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1620
}
1621
1622
CASE(_dcmpl):
1623
CASE(_dcmpg):
1624
{
1625
int r = VMdoubleCompare(STACK_DOUBLE(-3),
1626
STACK_DOUBLE(-1),
1627
(opcode == Bytecodes::_dcmpl ? -1 : 1));
1628
MORE_STACK(-4); // Pop
1629
SET_STACK_INT(r, 0);
1630
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1631
}
1632
1633
CASE(_lcmp):
1634
{
1635
int r = VMlongCompare(STACK_LONG(-3), STACK_LONG(-1));
1636
MORE_STACK(-4);
1637
SET_STACK_INT(r, 0);
1638
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1639
}
1640
1641
1642
/* Return from a method */
1643
1644
CASE(_areturn):
1645
CASE(_ireturn):
1646
CASE(_freturn):
1647
{
1648
// Allow a safepoint before returning to frame manager.
1649
SAFEPOINT;
1650
1651
goto handle_return;
1652
}
1653
1654
CASE(_lreturn):
1655
CASE(_dreturn):
1656
{
1657
// Allow a safepoint before returning to frame manager.
1658
SAFEPOINT;
1659
goto handle_return;
1660
}
1661
1662
CASE(_return_register_finalizer): {
1663
1664
oop rcvr = LOCALS_OBJECT(0);
1665
VERIFY_OOP(rcvr);
1666
if (rcvr->klass()->has_finalizer()) {
1667
CALL_VM(InterpreterRuntime::register_finalizer(THREAD, rcvr), handle_exception);
1668
}
1669
goto handle_return;
1670
}
1671
CASE(_return): {
1672
1673
// Allow a safepoint before returning to frame manager.
1674
SAFEPOINT;
1675
goto handle_return;
1676
}
1677
1678
/* Array access byte-codes */
1679
1680
/* Every array access byte-code starts out like this */
1681
// arrayOopDesc* arrObj = (arrayOopDesc*)STACK_OBJECT(arrayOff);
1682
#define ARRAY_INTRO(arrayOff) \
1683
arrayOop arrObj = (arrayOop)STACK_OBJECT(arrayOff); \
1684
jint index = STACK_INT(arrayOff + 1); \
1685
char message[jintAsStringSize]; \
1686
CHECK_NULL(arrObj); \
1687
if ((uint32_t)index >= (uint32_t)arrObj->length()) { \
1688
sprintf(message, "%d", index); \
1689
VM_JAVA_ERROR(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), \
1690
message, note_rangeCheck_trap); \
1691
}
1692
1693
/* 32-bit loads. These handle conversion from < 32-bit types */
1694
#define ARRAY_LOADTO32(T, T2, format, stackRes, extra) \
1695
{ \
1696
ARRAY_INTRO(-2); \
1697
(void)extra; \
1698
SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), \
1699
-2); \
1700
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
1701
}
1702
1703
/* 64-bit loads */
1704
#define ARRAY_LOADTO64(T,T2, stackRes, extra) \
1705
{ \
1706
ARRAY_INTRO(-2); \
1707
SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), -1); \
1708
(void)extra; \
1709
UPDATE_PC_AND_CONTINUE(1); \
1710
}
1711
1712
CASE(_iaload):
1713
ARRAY_LOADTO32(T_INT, jint, "%d", STACK_INT, 0);
1714
CASE(_faload):
1715
ARRAY_LOADTO32(T_FLOAT, jfloat, "%f", STACK_FLOAT, 0);
1716
CASE(_aaload): {
1717
ARRAY_INTRO(-2);
1718
SET_STACK_OBJECT(((objArrayOop) arrObj)->obj_at(index), -2);
1719
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1720
}
1721
CASE(_baload):
1722
ARRAY_LOADTO32(T_BYTE, jbyte, "%d", STACK_INT, 0);
1723
CASE(_caload):
1724
ARRAY_LOADTO32(T_CHAR, jchar, "%d", STACK_INT, 0);
1725
CASE(_saload):
1726
ARRAY_LOADTO32(T_SHORT, jshort, "%d", STACK_INT, 0);
1727
CASE(_laload):
1728
ARRAY_LOADTO64(T_LONG, jlong, STACK_LONG, 0);
1729
CASE(_daload):
1730
ARRAY_LOADTO64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);
1731
1732
/* 32-bit stores. These handle conversion to < 32-bit types */
1733
#define ARRAY_STOREFROM32(T, T2, format, stackSrc, extra) \
1734
{ \
1735
ARRAY_INTRO(-3); \
1736
(void)extra; \
1737
*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \
1738
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3); \
1739
}
1740
1741
/* 64-bit stores */
1742
#define ARRAY_STOREFROM64(T, T2, stackSrc, extra) \
1743
{ \
1744
ARRAY_INTRO(-4); \
1745
(void)extra; \
1746
*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \
1747
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -4); \
1748
}
1749
1750
CASE(_iastore):
1751
ARRAY_STOREFROM32(T_INT, jint, "%d", STACK_INT, 0);
1752
CASE(_fastore):
1753
ARRAY_STOREFROM32(T_FLOAT, jfloat, "%f", STACK_FLOAT, 0);
1754
/*
1755
* This one looks different because of the assignability check
1756
*/
1757
CASE(_aastore): {
1758
oop rhsObject = STACK_OBJECT(-1);
1759
VERIFY_OOP(rhsObject);
1760
ARRAY_INTRO( -3);
1761
// arrObj, index are set
1762
if (rhsObject != NULL) {
1763
/* Check assignability of rhsObject into arrObj */
1764
Klass* rhsKlass = rhsObject->klass(); // EBX (subclass)
1765
Klass* elemKlass = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX
1766
//
1767
// Check for compatibilty. This check must not GC!!
1768
// Seems way more expensive now that we must dispatch
1769
//
1770
if (rhsKlass != elemKlass && !rhsKlass->is_subtype_of(elemKlass)) { // ebx->is...
1771
// Decrement counter if subtype check failed.
1772
BI_PROFILE_SUBTYPECHECK_FAILED(rhsKlass);
1773
VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "", note_arrayCheck_trap);
1774
}
1775
// Profile checkcast with null_seen and receiver.
1776
BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/false, rhsKlass);
1777
} else {
1778
// Profile checkcast with null_seen and receiver.
1779
BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/true, NULL);
1780
}
1781
((objArrayOop) arrObj)->obj_at_put(index, rhsObject);
1782
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);
1783
}
1784
CASE(_bastore): {
1785
ARRAY_INTRO(-3);
1786
int item = STACK_INT(-1);
1787
// if it is a T_BOOLEAN array, mask the stored value to 0/1
1788
if (arrObj->klass() == Universe::boolArrayKlassObj()) {
1789
item &= 1;
1790
} else {
1791
assert(arrObj->klass() == Universe::byteArrayKlassObj(),
1792
"should be byte array otherwise");
1793
}
1794
((typeArrayOop)arrObj)->byte_at_put(index, item);
1795
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);
1796
}
1797
CASE(_castore):
1798
ARRAY_STOREFROM32(T_CHAR, jchar, "%d", STACK_INT, 0);
1799
CASE(_sastore):
1800
ARRAY_STOREFROM32(T_SHORT, jshort, "%d", STACK_INT, 0);
1801
CASE(_lastore):
1802
ARRAY_STOREFROM64(T_LONG, jlong, STACK_LONG, 0);
1803
CASE(_dastore):
1804
ARRAY_STOREFROM64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);
1805
1806
CASE(_arraylength):
1807
{
1808
arrayOop ary = (arrayOop) STACK_OBJECT(-1);
1809
CHECK_NULL(ary);
1810
SET_STACK_INT(ary->length(), -1);
1811
UPDATE_PC_AND_CONTINUE(1);
1812
}
1813
1814
/* monitorenter and monitorexit for locking/unlocking an object */
1815
1816
CASE(_monitorenter): {
1817
oop lockee = STACK_OBJECT(-1);
1818
// derefing's lockee ought to provoke implicit null check
1819
CHECK_NULL(lockee);
1820
// find a free monitor or one already allocated for this object
1821
// if we find a matching object then we need a new monitor
1822
// since this is recursive enter
1823
BasicObjectLock* limit = istate->monitor_base();
1824
BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1825
BasicObjectLock* entry = NULL;
1826
while (most_recent != limit ) {
1827
if (most_recent->obj() == NULL) entry = most_recent;
1828
else if (most_recent->obj() == lockee) break;
1829
most_recent++;
1830
}
1831
if (entry != NULL) {
1832
entry->set_obj(lockee);
1833
int success = false;
1834
uintptr_t epoch_mask_in_place = (uintptr_t)markOopDesc::epoch_mask_in_place;
1835
1836
markOop mark = lockee->mark();
1837
intptr_t hash = (intptr_t) markOopDesc::no_hash;
1838
// implies UseBiasedLocking
1839
if (mark->has_bias_pattern()) {
1840
uintptr_t thread_ident;
1841
uintptr_t anticipated_bias_locking_value;
1842
thread_ident = (uintptr_t)istate->thread();
1843
anticipated_bias_locking_value =
1844
(((uintptr_t)lockee->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) &
1845
~((uintptr_t) markOopDesc::age_mask_in_place);
1846
1847
if (anticipated_bias_locking_value == 0) {
1848
// already biased towards this thread, nothing to do
1849
if (PrintBiasedLockingStatistics) {
1850
(* BiasedLocking::biased_lock_entry_count_addr())++;
1851
}
1852
success = true;
1853
}
1854
else if ((anticipated_bias_locking_value & markOopDesc::biased_lock_mask_in_place) != 0) {
1855
// try revoke bias
1856
markOop header = lockee->klass()->prototype_header();
1857
if (hash != markOopDesc::no_hash) {
1858
header = header->copy_set_hash(hash);
1859
}
1860
if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), mark) == mark) {
1861
if (PrintBiasedLockingStatistics)
1862
(*BiasedLocking::revoked_lock_entry_count_addr())++;
1863
}
1864
}
1865
else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
1866
// try rebias
1867
markOop new_header = (markOop) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident);
1868
if (hash != markOopDesc::no_hash) {
1869
new_header = new_header->copy_set_hash(hash);
1870
}
1871
if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), mark) == mark) {
1872
if (PrintBiasedLockingStatistics)
1873
(* BiasedLocking::rebiased_lock_entry_count_addr())++;
1874
}
1875
else {
1876
CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1877
}
1878
success = true;
1879
}
1880
else {
1881
// try to bias towards thread in case object is anonymously biased
1882
markOop header = (markOop) ((uintptr_t) mark & ((uintptr_t)markOopDesc::biased_lock_mask_in_place |
1883
(uintptr_t)markOopDesc::age_mask_in_place |
1884
epoch_mask_in_place));
1885
if (hash != markOopDesc::no_hash) {
1886
header = header->copy_set_hash(hash);
1887
}
1888
markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
1889
// debugging hint
1890
DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
1891
if (Atomic::cmpxchg_ptr((void*)new_header, lockee->mark_addr(), header) == header) {
1892
if (PrintBiasedLockingStatistics)
1893
(* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
1894
}
1895
else {
1896
CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1897
}
1898
success = true;
1899
}
1900
}
1901
1902
// traditional lightweight locking
1903
if (!success) {
1904
markOop displaced = lockee->mark()->set_unlocked();
1905
entry->lock()->set_displaced_header(displaced);
1906
bool call_vm = UseHeavyMonitors;
1907
if (call_vm || Atomic::cmpxchg_ptr(entry, lockee->mark_addr(), displaced) != displaced) {
1908
// Is it simple recursive case?
1909
if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
1910
entry->lock()->set_displaced_header(NULL);
1911
} else {
1912
CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1913
}
1914
}
1915
}
1916
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1917
} else {
1918
istate->set_msg(more_monitors);
1919
UPDATE_PC_AND_RETURN(0); // Re-execute
1920
}
1921
}
1922
1923
CASE(_monitorexit): {
1924
oop lockee = STACK_OBJECT(-1);
1925
CHECK_NULL(lockee);
1926
// derefing's lockee ought to provoke implicit null check
1927
// find our monitor slot
1928
BasicObjectLock* limit = istate->monitor_base();
1929
BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1930
while (most_recent != limit ) {
1931
if ((most_recent)->obj() == lockee) {
1932
BasicLock* lock = most_recent->lock();
1933
markOop header = lock->displaced_header();
1934
most_recent->set_obj(NULL);
1935
if (!lockee->mark()->has_bias_pattern()) {
1936
bool call_vm = UseHeavyMonitors;
1937
// If it isn't recursive we either must swap old header or call the runtime
1938
if (header != NULL || call_vm) {
1939
if (call_vm || Atomic::cmpxchg_ptr(header, lockee->mark_addr(), lock) != lock) {
1940
// restore object for the slow case
1941
most_recent->set_obj(lockee);
1942
CALL_VM(InterpreterRuntime::monitorexit(THREAD, most_recent), handle_exception);
1943
}
1944
}
1945
}
1946
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1947
}
1948
most_recent++;
1949
}
1950
// Need to throw illegal monitor state exception
1951
CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1952
ShouldNotReachHere();
1953
}
1954
1955
/* All of the non-quick opcodes. */
1956
1957
/* -Set clobbersCpIndex true if the quickened opcode clobbers the
1958
* constant pool index in the instruction.
1959
*/
1960
CASE(_getfield):
1961
CASE(_getstatic):
1962
{
1963
u2 index;
1964
ConstantPoolCacheEntry* cache;
1965
index = Bytes::get_native_u2(pc+1);
1966
1967
// QQQ Need to make this as inlined as possible. Probably need to
1968
// split all the bytecode cases out so c++ compiler has a chance
1969
// for constant prop to fold everything possible away.
1970
1971
cache = cp->entry_at(index);
1972
if (!cache->is_resolved((Bytecodes::Code)opcode)) {
1973
CALL_VM(InterpreterRuntime::resolve_get_put(THREAD, (Bytecodes::Code)opcode),
1974
handle_exception);
1975
cache = cp->entry_at(index);
1976
}
1977
1978
#ifdef VM_JVMTI
1979
if (_jvmti_interp_events) {
1980
int *count_addr;
1981
oop obj;
1982
// Check to see if a field modification watch has been set
1983
// before we take the time to call into the VM.
1984
count_addr = (int *)JvmtiExport::get_field_access_count_addr();
1985
if ( *count_addr > 0 ) {
1986
if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {
1987
obj = (oop)NULL;
1988
} else {
1989
obj = (oop) STACK_OBJECT(-1);
1990
VERIFY_OOP(obj);
1991
}
1992
CALL_VM(InterpreterRuntime::post_field_access(THREAD,
1993
obj,
1994
cache),
1995
handle_exception);
1996
}
1997
}
1998
#endif /* VM_JVMTI */
1999
2000
oop obj;
2001
if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {
2002
Klass* k = cache->f1_as_klass();
2003
obj = k->java_mirror();
2004
MORE_STACK(1); // Assume single slot push
2005
} else {
2006
obj = (oop) STACK_OBJECT(-1);
2007
CHECK_NULL(obj);
2008
}
2009
2010
//
2011
// Now store the result on the stack
2012
//
2013
TosState tos_type = cache->flag_state();
2014
int field_offset = cache->f2_as_index();
2015
if (cache->is_volatile()) {
2016
if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
2017
OrderAccess::fence();
2018
}
2019
if (tos_type == atos) {
2020
VERIFY_OOP(obj->obj_field_acquire(field_offset));
2021
SET_STACK_OBJECT(obj->obj_field_acquire(field_offset), -1);
2022
} else if (tos_type == itos) {
2023
SET_STACK_INT(obj->int_field_acquire(field_offset), -1);
2024
} else if (tos_type == ltos) {
2025
SET_STACK_LONG(obj->long_field_acquire(field_offset), 0);
2026
MORE_STACK(1);
2027
} else if (tos_type == btos || tos_type == ztos) {
2028
SET_STACK_INT(obj->byte_field_acquire(field_offset), -1);
2029
} else if (tos_type == ctos) {
2030
SET_STACK_INT(obj->char_field_acquire(field_offset), -1);
2031
} else if (tos_type == stos) {
2032
SET_STACK_INT(obj->short_field_acquire(field_offset), -1);
2033
} else if (tos_type == ftos) {
2034
SET_STACK_FLOAT(obj->float_field_acquire(field_offset), -1);
2035
} else {
2036
SET_STACK_DOUBLE(obj->double_field_acquire(field_offset), 0);
2037
MORE_STACK(1);
2038
}
2039
} else {
2040
if (tos_type == atos) {
2041
VERIFY_OOP(obj->obj_field(field_offset));
2042
SET_STACK_OBJECT(obj->obj_field(field_offset), -1);
2043
} else if (tos_type == itos) {
2044
SET_STACK_INT(obj->int_field(field_offset), -1);
2045
} else if (tos_type == ltos) {
2046
SET_STACK_LONG(obj->long_field(field_offset), 0);
2047
MORE_STACK(1);
2048
} else if (tos_type == btos || tos_type == ztos) {
2049
SET_STACK_INT(obj->byte_field(field_offset), -1);
2050
} else if (tos_type == ctos) {
2051
SET_STACK_INT(obj->char_field(field_offset), -1);
2052
} else if (tos_type == stos) {
2053
SET_STACK_INT(obj->short_field(field_offset), -1);
2054
} else if (tos_type == ftos) {
2055
SET_STACK_FLOAT(obj->float_field(field_offset), -1);
2056
} else {
2057
SET_STACK_DOUBLE(obj->double_field(field_offset), 0);
2058
MORE_STACK(1);
2059
}
2060
}
2061
2062
UPDATE_PC_AND_CONTINUE(3);
2063
}
2064
2065
CASE(_putfield):
2066
CASE(_putstatic):
2067
{
2068
u2 index = Bytes::get_native_u2(pc+1);
2069
ConstantPoolCacheEntry* cache = cp->entry_at(index);
2070
if (!cache->is_resolved((Bytecodes::Code)opcode)) {
2071
CALL_VM(InterpreterRuntime::resolve_get_put(THREAD, (Bytecodes::Code)opcode),
2072
handle_exception);
2073
cache = cp->entry_at(index);
2074
}
2075
2076
#ifdef VM_JVMTI
2077
if (_jvmti_interp_events) {
2078
int *count_addr;
2079
oop obj;
2080
// Check to see if a field modification watch has been set
2081
// before we take the time to call into the VM.
2082
count_addr = (int *)JvmtiExport::get_field_modification_count_addr();
2083
if ( *count_addr > 0 ) {
2084
if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {
2085
obj = (oop)NULL;
2086
}
2087
else {
2088
if (cache->is_long() || cache->is_double()) {
2089
obj = (oop) STACK_OBJECT(-3);
2090
} else {
2091
obj = (oop) STACK_OBJECT(-2);
2092
}
2093
VERIFY_OOP(obj);
2094
}
2095
2096
CALL_VM(InterpreterRuntime::post_field_modification(THREAD,
2097
obj,
2098
cache,
2099
(jvalue *)STACK_SLOT(-1)),
2100
handle_exception);
2101
}
2102
}
2103
#endif /* VM_JVMTI */
2104
2105
// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
2106
// out so c++ compiler has a chance for constant prop to fold everything possible away.
2107
2108
oop obj;
2109
int count;
2110
TosState tos_type = cache->flag_state();
2111
2112
count = -1;
2113
if (tos_type == ltos || tos_type == dtos) {
2114
--count;
2115
}
2116
if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {
2117
Klass* k = cache->f1_as_klass();
2118
obj = k->java_mirror();
2119
} else {
2120
--count;
2121
obj = (oop) STACK_OBJECT(count);
2122
CHECK_NULL(obj);
2123
}
2124
2125
//
2126
// Now store the result
2127
//
2128
int field_offset = cache->f2_as_index();
2129
if (cache->is_volatile()) {
2130
if (tos_type == itos) {
2131
obj->release_int_field_put(field_offset, STACK_INT(-1));
2132
} else if (tos_type == atos) {
2133
VERIFY_OOP(STACK_OBJECT(-1));
2134
obj->release_obj_field_put(field_offset, STACK_OBJECT(-1));
2135
} else if (tos_type == btos) {
2136
obj->release_byte_field_put(field_offset, STACK_INT(-1));
2137
} else if (tos_type == ztos) {
2138
int bool_field = STACK_INT(-1); // only store LSB
2139
obj->release_byte_field_put(field_offset, (bool_field & 1));
2140
} else if (tos_type == ltos) {
2141
obj->release_long_field_put(field_offset, STACK_LONG(-1));
2142
} else if (tos_type == ctos) {
2143
obj->release_char_field_put(field_offset, STACK_INT(-1));
2144
} else if (tos_type == stos) {
2145
obj->release_short_field_put(field_offset, STACK_INT(-1));
2146
} else if (tos_type == ftos) {
2147
obj->release_float_field_put(field_offset, STACK_FLOAT(-1));
2148
} else {
2149
obj->release_double_field_put(field_offset, STACK_DOUBLE(-1));
2150
}
2151
OrderAccess::storeload();
2152
} else {
2153
if (tos_type == itos) {
2154
obj->int_field_put(field_offset, STACK_INT(-1));
2155
} else if (tos_type == atos) {
2156
VERIFY_OOP(STACK_OBJECT(-1));
2157
obj->obj_field_put(field_offset, STACK_OBJECT(-1));
2158
} else if (tos_type == btos) {
2159
obj->byte_field_put(field_offset, STACK_INT(-1));
2160
} else if (tos_type == ztos) {
2161
int bool_field = STACK_INT(-1); // only store LSB
2162
obj->byte_field_put(field_offset, (bool_field & 1));
2163
} else if (tos_type == ltos) {
2164
obj->long_field_put(field_offset, STACK_LONG(-1));
2165
} else if (tos_type == ctos) {
2166
obj->char_field_put(field_offset, STACK_INT(-1));
2167
} else if (tos_type == stos) {
2168
obj->short_field_put(field_offset, STACK_INT(-1));
2169
} else if (tos_type == ftos) {
2170
obj->float_field_put(field_offset, STACK_FLOAT(-1));
2171
} else {
2172
obj->double_field_put(field_offset, STACK_DOUBLE(-1));
2173
}
2174
}
2175
2176
UPDATE_PC_AND_TOS_AND_CONTINUE(3, count);
2177
}
2178
2179
CASE(_new): {
2180
u2 index = Bytes::get_Java_u2(pc+1);
2181
ConstantPool* constants = istate->method()->constants();
2182
if (!constants->tag_at(index).is_unresolved_klass()) {
2183
// Make sure klass is initialized and doesn't have a finalizer
2184
Klass* entry = constants->slot_at(index).get_klass();
2185
assert(entry->is_klass(), "Should be resolved klass");
2186
Klass* k_entry = (Klass*) entry;
2187
assert(k_entry->oop_is_instance(), "Should be InstanceKlass");
2188
InstanceKlass* ik = (InstanceKlass*) k_entry;
2189
if ( ik->is_initialized() && ik->can_be_fastpath_allocated() ) {
2190
size_t obj_size = ik->size_helper();
2191
oop result = NULL;
2192
// If the TLAB isn't pre-zeroed then we'll have to do it
2193
bool need_zero = !ZeroTLAB;
2194
if (UseTLAB) {
2195
result = (oop) THREAD->tlab().allocate(obj_size);
2196
}
2197
// Disable non-TLAB-based fast-path, because profiling requires that all
2198
// allocations go through InterpreterRuntime::_new() if THREAD->tlab().allocate
2199
// returns NULL.
2200
#ifndef CC_INTERP_PROFILE
2201
if (result == NULL) {
2202
need_zero = true;
2203
// Try allocate in shared eden
2204
retry:
2205
HeapWord* compare_to = *Universe::heap()->top_addr();
2206
HeapWord* new_top = compare_to + obj_size;
2207
if (new_top <= *Universe::heap()->end_addr()) {
2208
if (Atomic::cmpxchg_ptr(new_top, Universe::heap()->top_addr(), compare_to) != compare_to) {
2209
goto retry;
2210
}
2211
result = (oop) compare_to;
2212
}
2213
}
2214
#endif
2215
if (result != NULL) {
2216
// Initialize object (if nonzero size and need) and then the header
2217
if (need_zero ) {
2218
HeapWord* to_zero = (HeapWord*) result + sizeof(oopDesc) / oopSize;
2219
obj_size -= sizeof(oopDesc) / oopSize;
2220
if (obj_size > 0 ) {
2221
memset(to_zero, 0, obj_size * HeapWordSize);
2222
}
2223
}
2224
if (UseBiasedLocking) {
2225
result->set_mark(ik->prototype_header());
2226
} else {
2227
result->set_mark(markOopDesc::prototype());
2228
}
2229
result->set_klass_gap(0);
2230
result->set_klass(k_entry);
2231
// Must prevent reordering of stores for object initialization
2232
// with stores that publish the new object.
2233
OrderAccess::storestore();
2234
SET_STACK_OBJECT(result, 0);
2235
UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
2236
}
2237
}
2238
}
2239
// Slow case allocation
2240
CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),
2241
handle_exception);
2242
// Must prevent reordering of stores for object initialization
2243
// with stores that publish the new object.
2244
OrderAccess::storestore();
2245
SET_STACK_OBJECT(THREAD->vm_result(), 0);
2246
THREAD->set_vm_result(NULL);
2247
UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
2248
}
2249
CASE(_anewarray): {
2250
u2 index = Bytes::get_Java_u2(pc+1);
2251
jint size = STACK_INT(-1);
2252
CALL_VM(InterpreterRuntime::anewarray(THREAD, METHOD->constants(), index, size),
2253
handle_exception);
2254
// Must prevent reordering of stores for object initialization
2255
// with stores that publish the new object.
2256
OrderAccess::storestore();
2257
SET_STACK_OBJECT(THREAD->vm_result(), -1);
2258
THREAD->set_vm_result(NULL);
2259
UPDATE_PC_AND_CONTINUE(3);
2260
}
2261
CASE(_multianewarray): {
2262
jint dims = *(pc+3);
2263
jint size = STACK_INT(-1);
2264
// stack grows down, dimensions are up!
2265
jint *dimarray =
2266
(jint*)&topOfStack[dims * Interpreter::stackElementWords+
2267
Interpreter::stackElementWords-1];
2268
//adjust pointer to start of stack element
2269
CALL_VM(InterpreterRuntime::multianewarray(THREAD, dimarray),
2270
handle_exception);
2271
// Must prevent reordering of stores for object initialization
2272
// with stores that publish the new object.
2273
OrderAccess::storestore();
2274
SET_STACK_OBJECT(THREAD->vm_result(), -dims);
2275
THREAD->set_vm_result(NULL);
2276
UPDATE_PC_AND_TOS_AND_CONTINUE(4, -(dims-1));
2277
}
2278
CASE(_checkcast):
2279
if (STACK_OBJECT(-1) != NULL) {
2280
VERIFY_OOP(STACK_OBJECT(-1));
2281
u2 index = Bytes::get_Java_u2(pc+1);
2282
// Constant pool may have actual klass or unresolved klass. If it is
2283
// unresolved we must resolve it.
2284
if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
2285
CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
2286
}
2287
Klass* klassOf = (Klass*) METHOD->constants()->slot_at(index).get_klass();
2288
Klass* objKlass = STACK_OBJECT(-1)->klass(); // ebx
2289
//
2290
// Check for compatibilty. This check must not GC!!
2291
// Seems way more expensive now that we must dispatch.
2292
//
2293
if (objKlass != klassOf && !objKlass->is_subtype_of(klassOf)) {
2294
// Decrement counter at checkcast.
2295
BI_PROFILE_SUBTYPECHECK_FAILED(objKlass);
2296
ResourceMark rm(THREAD);
2297
const char* objName = objKlass->external_name();
2298
const char* klassName = klassOf->external_name();
2299
char* message = SharedRuntime::generate_class_cast_message(
2300
objName, klassName);
2301
VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message, note_classCheck_trap);
2302
}
2303
// Profile checkcast with null_seen and receiver.
2304
BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/false, objKlass);
2305
} else {
2306
// Profile checkcast with null_seen and receiver.
2307
BI_PROFILE_UPDATE_CHECKCAST(/*null_seen=*/true, NULL);
2308
}
2309
UPDATE_PC_AND_CONTINUE(3);
2310
2311
CASE(_instanceof):
2312
if (STACK_OBJECT(-1) == NULL) {
2313
SET_STACK_INT(0, -1);
2314
// Profile instanceof with null_seen and receiver.
2315
BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/true, NULL);
2316
} else {
2317
VERIFY_OOP(STACK_OBJECT(-1));
2318
u2 index = Bytes::get_Java_u2(pc+1);
2319
// Constant pool may have actual klass or unresolved klass. If it is
2320
// unresolved we must resolve it.
2321
if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
2322
CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
2323
}
2324
Klass* klassOf = (Klass*) METHOD->constants()->slot_at(index).get_klass();
2325
Klass* objKlass = STACK_OBJECT(-1)->klass();
2326
//
2327
// Check for compatibilty. This check must not GC!!
2328
// Seems way more expensive now that we must dispatch.
2329
//
2330
if ( objKlass == klassOf || objKlass->is_subtype_of(klassOf)) {
2331
SET_STACK_INT(1, -1);
2332
} else {
2333
SET_STACK_INT(0, -1);
2334
// Decrement counter at checkcast.
2335
BI_PROFILE_SUBTYPECHECK_FAILED(objKlass);
2336
}
2337
// Profile instanceof with null_seen and receiver.
2338
BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/false, objKlass);
2339
}
2340
UPDATE_PC_AND_CONTINUE(3);
2341
2342
CASE(_ldc_w):
2343
CASE(_ldc):
2344
{
2345
u2 index;
2346
bool wide = false;
2347
int incr = 2; // frequent case
2348
if (opcode == Bytecodes::_ldc) {
2349
index = pc[1];
2350
} else {
2351
index = Bytes::get_Java_u2(pc+1);
2352
incr = 3;
2353
wide = true;
2354
}
2355
2356
ConstantPool* constants = METHOD->constants();
2357
switch (constants->tag_at(index).value()) {
2358
case JVM_CONSTANT_Integer:
2359
SET_STACK_INT(constants->int_at(index), 0);
2360
break;
2361
2362
case JVM_CONSTANT_Float:
2363
SET_STACK_FLOAT(constants->float_at(index), 0);
2364
break;
2365
2366
case JVM_CONSTANT_String:
2367
{
2368
oop result = constants->resolved_references()->obj_at(index);
2369
if (result == NULL) {
2370
CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);
2371
SET_STACK_OBJECT(THREAD->vm_result(), 0);
2372
THREAD->set_vm_result(NULL);
2373
} else {
2374
VERIFY_OOP(result);
2375
SET_STACK_OBJECT(result, 0);
2376
}
2377
break;
2378
}
2379
2380
case JVM_CONSTANT_Class:
2381
VERIFY_OOP(constants->resolved_klass_at(index)->java_mirror());
2382
SET_STACK_OBJECT(constants->resolved_klass_at(index)->java_mirror(), 0);
2383
break;
2384
2385
case JVM_CONSTANT_UnresolvedClass:
2386
case JVM_CONSTANT_UnresolvedClassInError:
2387
CALL_VM(InterpreterRuntime::ldc(THREAD, wide), handle_exception);
2388
SET_STACK_OBJECT(THREAD->vm_result(), 0);
2389
THREAD->set_vm_result(NULL);
2390
break;
2391
2392
default: ShouldNotReachHere();
2393
}
2394
UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);
2395
}
2396
2397
CASE(_ldc2_w):
2398
{
2399
u2 index = Bytes::get_Java_u2(pc+1);
2400
2401
ConstantPool* constants = METHOD->constants();
2402
switch (constants->tag_at(index).value()) {
2403
2404
case JVM_CONSTANT_Long:
2405
SET_STACK_LONG(constants->long_at(index), 1);
2406
break;
2407
2408
case JVM_CONSTANT_Double:
2409
SET_STACK_DOUBLE(constants->double_at(index), 1);
2410
break;
2411
default: ShouldNotReachHere();
2412
}
2413
UPDATE_PC_AND_TOS_AND_CONTINUE(3, 2);
2414
}
2415
2416
CASE(_fast_aldc_w):
2417
CASE(_fast_aldc): {
2418
u2 index;
2419
int incr;
2420
if (opcode == Bytecodes::_fast_aldc) {
2421
index = pc[1];
2422
incr = 2;
2423
} else {
2424
index = Bytes::get_native_u2(pc+1);
2425
incr = 3;
2426
}
2427
2428
// We are resolved if the f1 field contains a non-null object (CallSite, etc.)
2429
// This kind of CP cache entry does not need to match the flags byte, because
2430
// there is a 1-1 relation between bytecode type and CP entry type.
2431
ConstantPool* constants = METHOD->constants();
2432
oop result = constants->resolved_references()->obj_at(index);
2433
if (result == NULL) {
2434
CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode),
2435
handle_exception);
2436
result = THREAD->vm_result();
2437
}
2438
2439
VERIFY_OOP(result);
2440
SET_STACK_OBJECT(result, 0);
2441
UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);
2442
}
2443
2444
CASE(_invokedynamic): {
2445
2446
if (!EnableInvokeDynamic) {
2447
// We should not encounter this bytecode if !EnableInvokeDynamic.
2448
// The verifier will stop it. However, if we get past the verifier,
2449
// this will stop the thread in a reasonable way, without crashing the JVM.
2450
CALL_VM(InterpreterRuntime::throw_IncompatibleClassChangeError(THREAD),
2451
handle_exception);
2452
ShouldNotReachHere();
2453
}
2454
2455
u4 index = Bytes::get_native_u4(pc+1);
2456
ConstantPoolCacheEntry* cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index);
2457
2458
// We are resolved if the resolved_references field contains a non-null object (CallSite, etc.)
2459
// This kind of CP cache entry does not need to match the flags byte, because
2460
// there is a 1-1 relation between bytecode type and CP entry type.
2461
if (! cache->is_resolved((Bytecodes::Code) opcode)) {
2462
CALL_VM(InterpreterRuntime::resolve_invokedynamic(THREAD),
2463
handle_exception);
2464
cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index);
2465
}
2466
2467
Method* method = cache->f1_as_method();
2468
if (VerifyOops) method->verify();
2469
2470
if (cache->has_appendix()) {
2471
ConstantPool* constants = METHOD->constants();
2472
SET_STACK_OBJECT(cache->appendix_if_resolved(constants), 0);
2473
MORE_STACK(1);
2474
}
2475
2476
istate->set_msg(call_method);
2477
istate->set_callee(method);
2478
istate->set_callee_entry_point(method->from_interpreted_entry());
2479
istate->set_bcp_advance(5);
2480
2481
// Invokedynamic has got a call counter, just like an invokestatic -> increment!
2482
BI_PROFILE_UPDATE_CALL();
2483
2484
UPDATE_PC_AND_RETURN(0); // I'll be back...
2485
}
2486
2487
CASE(_invokehandle): {
2488
2489
if (!EnableInvokeDynamic) {
2490
ShouldNotReachHere();
2491
}
2492
2493
u2 index = Bytes::get_native_u2(pc+1);
2494
ConstantPoolCacheEntry* cache = cp->entry_at(index);
2495
2496
if (! cache->is_resolved((Bytecodes::Code) opcode)) {
2497
CALL_VM(InterpreterRuntime::resolve_invokehandle(THREAD),
2498
handle_exception);
2499
cache = cp->entry_at(index);
2500
}
2501
2502
Method* method = cache->f1_as_method();
2503
if (VerifyOops) method->verify();
2504
2505
if (cache->has_appendix()) {
2506
ConstantPool* constants = METHOD->constants();
2507
SET_STACK_OBJECT(cache->appendix_if_resolved(constants), 0);
2508
MORE_STACK(1);
2509
}
2510
2511
istate->set_msg(call_method);
2512
istate->set_callee(method);
2513
istate->set_callee_entry_point(method->from_interpreted_entry());
2514
istate->set_bcp_advance(3);
2515
2516
// Invokehandle has got a call counter, just like a final call -> increment!
2517
BI_PROFILE_UPDATE_FINALCALL();
2518
2519
UPDATE_PC_AND_RETURN(0); // I'll be back...
2520
}
2521
2522
CASE(_invokeinterface): {
2523
u2 index = Bytes::get_native_u2(pc+1);
2524
2525
// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
2526
// out so c++ compiler has a chance for constant prop to fold everything possible away.
2527
2528
ConstantPoolCacheEntry* cache = cp->entry_at(index);
2529
if (!cache->is_resolved((Bytecodes::Code)opcode)) {
2530
CALL_VM(InterpreterRuntime::resolve_invoke(THREAD, (Bytecodes::Code)opcode),
2531
handle_exception);
2532
cache = cp->entry_at(index);
2533
}
2534
2535
istate->set_msg(call_method);
2536
2537
// Special case of invokeinterface called for virtual method of
2538
// java.lang.Object. See cpCacheOop.cpp for details.
2539
// This code isn't produced by javac, but could be produced by
2540
// another compliant java compiler.
2541
if (cache->is_forced_virtual()) {
2542
Method* callee;
2543
CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
2544
if (cache->is_vfinal()) {
2545
callee = cache->f2_as_vfinal_method();
2546
// Profile 'special case of invokeinterface' final call.
2547
BI_PROFILE_UPDATE_FINALCALL();
2548
} else {
2549
// Get receiver.
2550
int parms = cache->parameter_size();
2551
// Same comments as invokevirtual apply here.
2552
oop rcvr = STACK_OBJECT(-parms);
2553
VERIFY_OOP(rcvr);
2554
InstanceKlass* rcvrKlass = (InstanceKlass*)rcvr->klass();
2555
callee = (Method*) rcvrKlass->start_of_vtable()[ cache->f2_as_index()];
2556
// Profile 'special case of invokeinterface' virtual call.
2557
BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
2558
}
2559
istate->set_callee(callee);
2560
istate->set_callee_entry_point(callee->from_interpreted_entry());
2561
#ifdef VM_JVMTI
2562
if (JvmtiExport::can_post_interpreter_events() && THREAD->is_interp_only_mode()) {
2563
istate->set_callee_entry_point(callee->interpreter_entry());
2564
}
2565
#endif /* VM_JVMTI */
2566
istate->set_bcp_advance(5);
2567
UPDATE_PC_AND_RETURN(0); // I'll be back...
2568
}
2569
2570
// this could definitely be cleaned up QQQ
2571
Method* callee;
2572
Method *interface_method = cache->f2_as_interface_method();
2573
InstanceKlass* iclass = interface_method->method_holder();
2574
2575
// get receiver
2576
int parms = cache->parameter_size();
2577
oop rcvr = STACK_OBJECT(-parms);
2578
CHECK_NULL(rcvr);
2579
InstanceKlass* int2 = (InstanceKlass*) rcvr->klass();
2580
2581
// Receiver subtype check against resolved interface klass (REFC).
2582
{
2583
Klass* refc = cache->f1_as_klass();
2584
itableOffsetEntry* scan;
2585
for (scan = (itableOffsetEntry*) int2->start_of_itable();
2586
scan->interface_klass() != NULL;
2587
scan++) {
2588
if (scan->interface_klass() == refc) {
2589
break;
2590
}
2591
}
2592
// Check that the entry is non-null. A null entry means
2593
// that the receiver class doesn't implement the
2594
// interface, and wasn't the same as when the caller was
2595
// compiled.
2596
if (scan->interface_klass() == NULL) {
2597
VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "", note_no_trap);
2598
}
2599
}
2600
2601
itableOffsetEntry* ki = (itableOffsetEntry*) int2->start_of_itable();
2602
int i;
2603
for ( i = 0 ; i < int2->itable_length() ; i++, ki++ ) {
2604
if (ki->interface_klass() == iclass) break;
2605
}
2606
// If the interface isn't found, this class doesn't implement this
2607
// interface. The link resolver checks this but only for the first
2608
// time this interface is called.
2609
if (i == int2->itable_length()) {
2610
VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "", note_no_trap);
2611
}
2612
int mindex = interface_method->itable_index();
2613
2614
itableMethodEntry* im = ki->first_method_entry(rcvr->klass());
2615
callee = im[mindex].method();
2616
if (callee == NULL) {
2617
VM_JAVA_ERROR(vmSymbols::java_lang_AbstractMethodError(), "", note_no_trap);
2618
}
2619
2620
// Profile virtual call.
2621
BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
2622
2623
istate->set_callee(callee);
2624
istate->set_callee_entry_point(callee->from_interpreted_entry());
2625
#ifdef VM_JVMTI
2626
if (JvmtiExport::can_post_interpreter_events() && THREAD->is_interp_only_mode()) {
2627
istate->set_callee_entry_point(callee->interpreter_entry());
2628
}
2629
#endif /* VM_JVMTI */
2630
istate->set_bcp_advance(5);
2631
UPDATE_PC_AND_RETURN(0); // I'll be back...
2632
}
2633
2634
CASE(_invokevirtual):
2635
CASE(_invokespecial):
2636
CASE(_invokestatic): {
2637
u2 index = Bytes::get_native_u2(pc+1);
2638
2639
ConstantPoolCacheEntry* cache = cp->entry_at(index);
2640
// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
2641
// out so c++ compiler has a chance for constant prop to fold everything possible away.
2642
2643
if (!cache->is_resolved((Bytecodes::Code)opcode)) {
2644
CALL_VM(InterpreterRuntime::resolve_invoke(THREAD, (Bytecodes::Code)opcode),
2645
handle_exception);
2646
cache = cp->entry_at(index);
2647
}
2648
2649
istate->set_msg(call_method);
2650
{
2651
Method* callee;
2652
if ((Bytecodes::Code)opcode == Bytecodes::_invokevirtual) {
2653
CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
2654
if (cache->is_vfinal()) {
2655
callee = cache->f2_as_vfinal_method();
2656
// Profile final call.
2657
BI_PROFILE_UPDATE_FINALCALL();
2658
} else {
2659
// get receiver
2660
int parms = cache->parameter_size();
2661
// this works but needs a resourcemark and seems to create a vtable on every call:
2662
// Method* callee = rcvr->klass()->vtable()->method_at(cache->f2_as_index());
2663
//
2664
// this fails with an assert
2665
// InstanceKlass* rcvrKlass = InstanceKlass::cast(STACK_OBJECT(-parms)->klass());
2666
// but this works
2667
oop rcvr = STACK_OBJECT(-parms);
2668
VERIFY_OOP(rcvr);
2669
InstanceKlass* rcvrKlass = (InstanceKlass*)rcvr->klass();
2670
/*
2671
Executing this code in java.lang.String:
2672
public String(char value[]) {
2673
this.count = value.length;
2674
this.value = (char[])value.clone();
2675
}
2676
2677
a find on rcvr->klass() reports:
2678
{type array char}{type array class}
2679
- klass: {other class}
2680
2681
but using InstanceKlass::cast(STACK_OBJECT(-parms)->klass()) causes in assertion failure
2682
because rcvr->klass()->oop_is_instance() == 0
2683
However it seems to have a vtable in the right location. Huh?
2684
2685
*/
2686
callee = (Method*) rcvrKlass->start_of_vtable()[ cache->f2_as_index()];
2687
// Profile virtual call.
2688
BI_PROFILE_UPDATE_VIRTUALCALL(rcvr->klass());
2689
}
2690
} else {
2691
if ((Bytecodes::Code)opcode == Bytecodes::_invokespecial) {
2692
CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
2693
}
2694
callee = cache->f1_as_method();
2695
2696
// Profile call.
2697
BI_PROFILE_UPDATE_CALL();
2698
}
2699
2700
istate->set_callee(callee);
2701
istate->set_callee_entry_point(callee->from_interpreted_entry());
2702
#ifdef VM_JVMTI
2703
if (JvmtiExport::can_post_interpreter_events() && THREAD->is_interp_only_mode()) {
2704
istate->set_callee_entry_point(callee->interpreter_entry());
2705
}
2706
#endif /* VM_JVMTI */
2707
istate->set_bcp_advance(3);
2708
UPDATE_PC_AND_RETURN(0); // I'll be back...
2709
}
2710
}
2711
2712
/* Allocate memory for a new java object. */
2713
2714
CASE(_newarray): {
2715
BasicType atype = (BasicType) *(pc+1);
2716
jint size = STACK_INT(-1);
2717
CALL_VM(InterpreterRuntime::newarray(THREAD, atype, size),
2718
handle_exception);
2719
// Must prevent reordering of stores for object initialization
2720
// with stores that publish the new object.
2721
OrderAccess::storestore();
2722
SET_STACK_OBJECT(THREAD->vm_result(), -1);
2723
THREAD->set_vm_result(NULL);
2724
2725
UPDATE_PC_AND_CONTINUE(2);
2726
}
2727
2728
/* Throw an exception. */
2729
2730
CASE(_athrow): {
2731
oop except_oop = STACK_OBJECT(-1);
2732
CHECK_NULL(except_oop);
2733
// set pending_exception so we use common code
2734
THREAD->set_pending_exception(except_oop, NULL, 0);
2735
goto handle_exception;
2736
}
2737
2738
/* goto and jsr. They are exactly the same except jsr pushes
2739
* the address of the next instruction first.
2740
*/
2741
2742
CASE(_jsr): {
2743
/* push bytecode index on stack */
2744
SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 3), 0);
2745
MORE_STACK(1);
2746
/* FALL THROUGH */
2747
}
2748
2749
CASE(_goto):
2750
{
2751
int16_t offset = (int16_t)Bytes::get_Java_u2(pc + 1);
2752
// Profile jump.
2753
BI_PROFILE_UPDATE_JUMP();
2754
address branch_pc = pc;
2755
UPDATE_PC(offset);
2756
DO_BACKEDGE_CHECKS(offset, branch_pc);
2757
CONTINUE;
2758
}
2759
2760
CASE(_jsr_w): {
2761
/* push return address on the stack */
2762
SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 5), 0);
2763
MORE_STACK(1);
2764
/* FALL THROUGH */
2765
}
2766
2767
CASE(_goto_w):
2768
{
2769
int32_t offset = Bytes::get_Java_u4(pc + 1);
2770
// Profile jump.
2771
BI_PROFILE_UPDATE_JUMP();
2772
address branch_pc = pc;
2773
UPDATE_PC(offset);
2774
DO_BACKEDGE_CHECKS(offset, branch_pc);
2775
CONTINUE;
2776
}
2777
2778
/* return from a jsr or jsr_w */
2779
2780
CASE(_ret): {
2781
// Profile ret.
2782
BI_PROFILE_UPDATE_RET(/*bci=*/((int)(intptr_t)(LOCALS_ADDR(pc[1]))));
2783
// Now, update the pc.
2784
pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(pc[1]));
2785
UPDATE_PC_AND_CONTINUE(0);
2786
}
2787
2788
/* debugger breakpoint */
2789
2790
CASE(_breakpoint): {
2791
Bytecodes::Code original_bytecode;
2792
DECACHE_STATE();
2793
SET_LAST_JAVA_FRAME();
2794
original_bytecode = InterpreterRuntime::get_original_bytecode_at(THREAD,
2795
METHOD, pc);
2796
RESET_LAST_JAVA_FRAME();
2797
CACHE_STATE();
2798
if (THREAD->has_pending_exception()) goto handle_exception;
2799
CALL_VM(InterpreterRuntime::_breakpoint(THREAD, METHOD, pc),
2800
handle_exception);
2801
2802
opcode = (jubyte)original_bytecode;
2803
goto opcode_switch;
2804
}
2805
2806
DEFAULT:
2807
fatal(err_msg("Unimplemented opcode %d = %s", opcode,
2808
Bytecodes::name((Bytecodes::Code)opcode)));
2809
goto finish;
2810
2811
} /* switch(opc) */
2812
2813
2814
#ifdef USELABELS
2815
check_for_exception:
2816
#endif
2817
{
2818
if (!THREAD->has_pending_exception()) {
2819
CONTINUE;
2820
}
2821
/* We will be gcsafe soon, so flush our state. */
2822
DECACHE_PC();
2823
goto handle_exception;
2824
}
2825
do_continue: ;
2826
2827
} /* while (1) interpreter loop */
2828
2829
2830
// An exception exists in the thread state see whether this activation can handle it
2831
handle_exception: {
2832
2833
HandleMarkCleaner __hmc(THREAD);
2834
Handle except_oop(THREAD, THREAD->pending_exception());
2835
// Prevent any subsequent HandleMarkCleaner in the VM
2836
// from freeing the except_oop handle.
2837
HandleMark __hm(THREAD);
2838
2839
THREAD->clear_pending_exception();
2840
assert(except_oop(), "No exception to process");
2841
intptr_t continuation_bci;
2842
// expression stack is emptied
2843
topOfStack = istate->stack_base() - Interpreter::stackElementWords;
2844
CALL_VM(continuation_bci = (intptr_t)InterpreterRuntime::exception_handler_for_exception(THREAD, except_oop()),
2845
handle_exception);
2846
2847
except_oop = THREAD->vm_result();
2848
THREAD->set_vm_result(NULL);
2849
if (continuation_bci >= 0) {
2850
// Place exception on top of stack
2851
SET_STACK_OBJECT(except_oop(), 0);
2852
MORE_STACK(1);
2853
pc = METHOD->code_base() + continuation_bci;
2854
if (TraceExceptions) {
2855
ttyLocker ttyl;
2856
ResourceMark rm;
2857
tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), p2i(except_oop()));
2858
tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string());
2859
tty->print_cr(" at bci %d, continuing at %d for thread " INTPTR_FORMAT,
2860
(int)(istate->bcp() - METHOD->code_base()),
2861
(int)continuation_bci, p2i(THREAD));
2862
}
2863
// for AbortVMOnException flag
2864
NOT_PRODUCT(Exceptions::debug_check_abort(except_oop));
2865
2866
// Update profiling data.
2867
BI_PROFILE_ALIGN_TO_CURRENT_BCI();
2868
goto run;
2869
}
2870
if (TraceExceptions) {
2871
ttyLocker ttyl;
2872
ResourceMark rm;
2873
tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", except_oop->print_value_string(), p2i(except_oop()));
2874
tty->print_cr(" thrown in interpreter method <%s>", METHOD->print_value_string());
2875
tty->print_cr(" at bci %d, unwinding for thread " INTPTR_FORMAT,
2876
(int)(istate->bcp() - METHOD->code_base()),
2877
p2i(THREAD));
2878
}
2879
// for AbortVMOnException flag
2880
NOT_PRODUCT(Exceptions::debug_check_abort(except_oop));
2881
// No handler in this activation, unwind and try again
2882
THREAD->set_pending_exception(except_oop(), NULL, 0);
2883
goto handle_return;
2884
} // handle_exception:
2885
2886
// Return from an interpreter invocation with the result of the interpretation
2887
// on the top of the Java Stack (or a pending exception)
2888
2889
handle_Pop_Frame: {
2890
2891
// We don't really do anything special here except we must be aware
2892
// that we can get here without ever locking the method (if sync).
2893
// Also we skip the notification of the exit.
2894
2895
istate->set_msg(popping_frame);
2896
// Clear pending so while the pop is in process
2897
// we don't start another one if a call_vm is done.
2898
THREAD->clr_pop_frame_pending();
2899
// Let interpreter (only) see the we're in the process of popping a frame
2900
THREAD->set_pop_frame_in_process();
2901
2902
goto handle_return;
2903
2904
} // handle_Pop_Frame
2905
2906
// ForceEarlyReturn ends a method, and returns to the caller with a return value
2907
// given by the invoker of the early return.
2908
handle_Early_Return: {
2909
2910
istate->set_msg(early_return);
2911
2912
// Clear expression stack.
2913
topOfStack = istate->stack_base() - Interpreter::stackElementWords;
2914
2915
JvmtiThreadState *ts = THREAD->jvmti_thread_state();
2916
2917
// Push the value to be returned.
2918
switch (istate->method()->result_type()) {
2919
case T_BOOLEAN:
2920
case T_SHORT:
2921
case T_BYTE:
2922
case T_CHAR:
2923
case T_INT:
2924
SET_STACK_INT(ts->earlyret_value().i, 0);
2925
MORE_STACK(1);
2926
break;
2927
case T_LONG:
2928
SET_STACK_LONG(ts->earlyret_value().j, 1);
2929
MORE_STACK(2);
2930
break;
2931
case T_FLOAT:
2932
SET_STACK_FLOAT(ts->earlyret_value().f, 0);
2933
MORE_STACK(1);
2934
break;
2935
case T_DOUBLE:
2936
SET_STACK_DOUBLE(ts->earlyret_value().d, 1);
2937
MORE_STACK(2);
2938
break;
2939
case T_ARRAY:
2940
case T_OBJECT:
2941
SET_STACK_OBJECT(ts->earlyret_oop(), 0);
2942
MORE_STACK(1);
2943
break;
2944
}
2945
2946
ts->clr_earlyret_value();
2947
ts->set_earlyret_oop(NULL);
2948
ts->clr_earlyret_pending();
2949
2950
// Fall through to handle_return.
2951
2952
} // handle_Early_Return
2953
2954
handle_return: {
2955
// A storestore barrier is required to order initialization of
2956
// final fields with publishing the reference to the object that
2957
// holds the field. Without the barrier the value of final fields
2958
// can be observed to change.
2959
OrderAccess::storestore();
2960
2961
DECACHE_STATE();
2962
2963
bool suppress_error = istate->msg() == popping_frame || istate->msg() == early_return;
2964
bool suppress_exit_event = THREAD->has_pending_exception() || istate->msg() == popping_frame;
2965
Handle original_exception(THREAD, THREAD->pending_exception());
2966
Handle illegal_state_oop(THREAD, NULL);
2967
2968
// We'd like a HandleMark here to prevent any subsequent HandleMarkCleaner
2969
// in any following VM entries from freeing our live handles, but illegal_state_oop
2970
// isn't really allocated yet and so doesn't become live until later and
2971
// in unpredicatable places. Instead we must protect the places where we enter the
2972
// VM. It would be much simpler (and safer) if we could allocate a real handle with
2973
// a NULL oop in it and then overwrite the oop later as needed. This isn't
2974
// unfortunately isn't possible.
2975
2976
THREAD->clear_pending_exception();
2977
2978
//
2979
// As far as we are concerned we have returned. If we have a pending exception
2980
// that will be returned as this invocation's result. However if we get any
2981
// exception(s) while checking monitor state one of those IllegalMonitorStateExceptions
2982
// will be our final result (i.e. monitor exception trumps a pending exception).
2983
//
2984
2985
// If we never locked the method (or really passed the point where we would have),
2986
// there is no need to unlock it (or look for other monitors), since that
2987
// could not have happened.
2988
2989
if (THREAD->do_not_unlock()) {
2990
2991
// Never locked, reset the flag now because obviously any caller must
2992
// have passed their point of locking for us to have gotten here.
2993
2994
THREAD->clr_do_not_unlock();
2995
} else {
2996
// At this point we consider that we have returned. We now check that the
2997
// locks were properly block structured. If we find that they were not
2998
// used properly we will return with an illegal monitor exception.
2999
// The exception is checked by the caller not the callee since this
3000
// checking is considered to be part of the invocation and therefore
3001
// in the callers scope (JVM spec 8.13).
3002
//
3003
// Another weird thing to watch for is if the method was locked
3004
// recursively and then not exited properly. This means we must
3005
// examine all the entries in reverse time(and stack) order and
3006
// unlock as we find them. If we find the method monitor before
3007
// we are at the initial entry then we should throw an exception.
3008
// It is not clear the template based interpreter does this
3009
// correctly
3010
3011
BasicObjectLock* base = istate->monitor_base();
3012
BasicObjectLock* end = (BasicObjectLock*) istate->stack_base();
3013
bool method_unlock_needed = METHOD->is_synchronized();
3014
// We know the initial monitor was used for the method don't check that
3015
// slot in the loop
3016
if (method_unlock_needed) base--;
3017
3018
// Check all the monitors to see they are unlocked. Install exception if found to be locked.
3019
while (end < base) {
3020
oop lockee = end->obj();
3021
if (lockee != NULL) {
3022
BasicLock* lock = end->lock();
3023
markOop header = lock->displaced_header();
3024
end->set_obj(NULL);
3025
3026
if (!lockee->mark()->has_bias_pattern()) {
3027
// If it isn't recursive we either must swap old header or call the runtime
3028
if (header != NULL) {
3029
if (Atomic::cmpxchg_ptr(header, lockee->mark_addr(), lock) != lock) {
3030
// restore object for the slow case
3031
end->set_obj(lockee);
3032
{
3033
// Prevent any HandleMarkCleaner from freeing our live handles
3034
HandleMark __hm(THREAD);
3035
CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, end));
3036
}
3037
}
3038
}
3039
}
3040
// One error is plenty
3041
if (illegal_state_oop() == NULL && !suppress_error) {
3042
{
3043
// Prevent any HandleMarkCleaner from freeing our live handles
3044
HandleMark __hm(THREAD);
3045
CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3046
}
3047
assert(THREAD->has_pending_exception(), "Lost our exception!");
3048
illegal_state_oop = THREAD->pending_exception();
3049
THREAD->clear_pending_exception();
3050
}
3051
}
3052
end++;
3053
}
3054
// Unlock the method if needed
3055
if (method_unlock_needed) {
3056
if (base->obj() == NULL) {
3057
// The method is already unlocked this is not good.
3058
if (illegal_state_oop() == NULL && !suppress_error) {
3059
{
3060
// Prevent any HandleMarkCleaner from freeing our live handles
3061
HandleMark __hm(THREAD);
3062
CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3063
}
3064
assert(THREAD->has_pending_exception(), "Lost our exception!");
3065
illegal_state_oop = THREAD->pending_exception();
3066
THREAD->clear_pending_exception();
3067
}
3068
} else {
3069
//
3070
// The initial monitor is always used for the method
3071
// However if that slot is no longer the oop for the method it was unlocked
3072
// and reused by something that wasn't unlocked!
3073
//
3074
// deopt can come in with rcvr dead because c2 knows
3075
// its value is preserved in the monitor. So we can't use locals[0] at all
3076
// and must use first monitor slot.
3077
//
3078
oop rcvr = base->obj();
3079
if (rcvr == NULL) {
3080
if (!suppress_error) {
3081
VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "", note_nullCheck_trap);
3082
illegal_state_oop = THREAD->pending_exception();
3083
THREAD->clear_pending_exception();
3084
}
3085
} else if (UseHeavyMonitors) {
3086
{
3087
// Prevent any HandleMarkCleaner from freeing our live handles.
3088
HandleMark __hm(THREAD);
3089
CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base));
3090
}
3091
if (THREAD->has_pending_exception()) {
3092
if (!suppress_error) illegal_state_oop = THREAD->pending_exception();
3093
THREAD->clear_pending_exception();
3094
}
3095
} else {
3096
BasicLock* lock = base->lock();
3097
markOop header = lock->displaced_header();
3098
base->set_obj(NULL);
3099
3100
if (!rcvr->mark()->has_bias_pattern()) {
3101
base->set_obj(NULL);
3102
// If it isn't recursive we either must swap old header or call the runtime
3103
if (header != NULL) {
3104
if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {
3105
// restore object for the slow case
3106
base->set_obj(rcvr);
3107
{
3108
// Prevent any HandleMarkCleaner from freeing our live handles
3109
HandleMark __hm(THREAD);
3110
CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base));
3111
}
3112
if (THREAD->has_pending_exception()) {
3113
if (!suppress_error) illegal_state_oop = THREAD->pending_exception();
3114
THREAD->clear_pending_exception();
3115
}
3116
}
3117
}
3118
}
3119
}
3120
}
3121
}
3122
}
3123
// Clear the do_not_unlock flag now.
3124
THREAD->clr_do_not_unlock();
3125
3126
//
3127
// Notify jvmti/jvmdi
3128
//
3129
// NOTE: we do not notify a method_exit if we have a pending exception,
3130
// including an exception we generate for unlocking checks. In the former
3131
// case, JVMDI has already been notified by our call for the exception handler
3132
// and in both cases as far as JVMDI is concerned we have already returned.
3133
// If we notify it again JVMDI will be all confused about how many frames
3134
// are still on the stack (4340444).
3135
//
3136
// NOTE Further! It turns out the the JVMTI spec in fact expects to see
3137
// method_exit events whenever we leave an activation unless it was done
3138
// for popframe. This is nothing like jvmdi. However we are passing the
3139
// tests at the moment (apparently because they are jvmdi based) so rather
3140
// than change this code and possibly fail tests we will leave it alone
3141
// (with this note) in anticipation of changing the vm and the tests
3142
// simultaneously.
3143
3144
3145
//
3146
suppress_exit_event = suppress_exit_event || illegal_state_oop() != NULL;
3147
3148
3149
3150
#ifdef VM_JVMTI
3151
if (_jvmti_interp_events) {
3152
// Whenever JVMTI puts a thread in interp_only_mode, method
3153
// entry/exit events are sent for that thread to track stack depth.
3154
if ( !suppress_exit_event && THREAD->is_interp_only_mode() ) {
3155
{
3156
// Prevent any HandleMarkCleaner from freeing our live handles
3157
HandleMark __hm(THREAD);
3158
CALL_VM_NOCHECK(InterpreterRuntime::post_method_exit(THREAD));
3159
}
3160
}
3161
}
3162
#endif /* VM_JVMTI */
3163
3164
//
3165
// See if we are returning any exception
3166
// A pending exception that was pending prior to a possible popping frame
3167
// overrides the popping frame.
3168
//
3169
assert(!suppress_error || (suppress_error && illegal_state_oop() == NULL), "Error was not suppressed");
3170
if (illegal_state_oop() != NULL || original_exception() != NULL) {
3171
// Inform the frame manager we have no result.
3172
istate->set_msg(throwing_exception);
3173
if (illegal_state_oop() != NULL)
3174
THREAD->set_pending_exception(illegal_state_oop(), NULL, 0);
3175
else
3176
THREAD->set_pending_exception(original_exception(), NULL, 0);
3177
UPDATE_PC_AND_RETURN(0);
3178
}
3179
3180
if (istate->msg() == popping_frame) {
3181
// Make it simpler on the assembly code and set the message for the frame pop.
3182
// returns
3183
if (istate->prev() == NULL) {
3184
// We must be returning to a deoptimized frame (because popframe only happens between
3185
// two interpreted frames). We need to save the current arguments in C heap so that
3186
// the deoptimized frame when it restarts can copy the arguments to its expression
3187
// stack and re-execute the call. We also have to notify deoptimization that this
3188
// has occurred and to pick the preserved args copy them to the deoptimized frame's
3189
// java expression stack. Yuck.
3190
//
3191
THREAD->popframe_preserve_args(in_ByteSize(METHOD->size_of_parameters() * wordSize),
3192
LOCALS_SLOT(METHOD->size_of_parameters() - 1));
3193
THREAD->set_popframe_condition_bit(JavaThread::popframe_force_deopt_reexecution_bit);
3194
}
3195
} else {
3196
istate->set_msg(return_from_method);
3197
}
3198
3199
// Normal return
3200
// Advance the pc and return to frame manager
3201
UPDATE_PC_AND_RETURN(1);
3202
} /* handle_return: */
3203
3204
// This is really a fatal error return
3205
3206
finish:
3207
DECACHE_TOS();
3208
DECACHE_PC();
3209
3210
return;
3211
}
3212
3213
/*
3214
* All the code following this point is only produced once and is not present
3215
* in the JVMTI version of the interpreter
3216
*/
3217
3218
#ifndef VM_JVMTI
3219
3220
// This constructor should only be used to contruct the object to signal
3221
// interpreter initialization. All other instances should be created by
3222
// the frame manager.
3223
BytecodeInterpreter::BytecodeInterpreter(messages msg) {
3224
if (msg != initialize) ShouldNotReachHere();
3225
_msg = msg;
3226
_self_link = this;
3227
_prev_link = NULL;
3228
}
3229
3230
// Inline static functions for Java Stack and Local manipulation
3231
3232
// The implementations are platform dependent. We have to worry about alignment
3233
// issues on some machines which can change on the same platform depending on
3234
// whether it is an LP64 machine also.
3235
address BytecodeInterpreter::stack_slot(intptr_t *tos, int offset) {
3236
return (address) tos[Interpreter::expr_index_at(-offset)];
3237
}
3238
3239
jint BytecodeInterpreter::stack_int(intptr_t *tos, int offset) {
3240
return *((jint*) &tos[Interpreter::expr_index_at(-offset)]);
3241
}
3242
3243
jfloat BytecodeInterpreter::stack_float(intptr_t *tos, int offset) {
3244
return *((jfloat *) &tos[Interpreter::expr_index_at(-offset)]);
3245
}
3246
3247
oop BytecodeInterpreter::stack_object(intptr_t *tos, int offset) {
3248
return cast_to_oop(tos [Interpreter::expr_index_at(-offset)]);
3249
}
3250
3251
jdouble BytecodeInterpreter::stack_double(intptr_t *tos, int offset) {
3252
return ((VMJavaVal64*) &tos[Interpreter::expr_index_at(-offset)])->d;
3253
}
3254
3255
jlong BytecodeInterpreter::stack_long(intptr_t *tos, int offset) {
3256
return ((VMJavaVal64 *) &tos[Interpreter::expr_index_at(-offset)])->l;
3257
}
3258
3259
// only used for value types
3260
void BytecodeInterpreter::set_stack_slot(intptr_t *tos, address value,
3261
int offset) {
3262
*((address *)&tos[Interpreter::expr_index_at(-offset)]) = value;
3263
}
3264
3265
void BytecodeInterpreter::set_stack_int(intptr_t *tos, int value,
3266
int offset) {
3267
*((jint *)&tos[Interpreter::expr_index_at(-offset)]) = value;
3268
}
3269
3270
void BytecodeInterpreter::set_stack_float(intptr_t *tos, jfloat value,
3271
int offset) {
3272
*((jfloat *)&tos[Interpreter::expr_index_at(-offset)]) = value;
3273
}
3274
3275
void BytecodeInterpreter::set_stack_object(intptr_t *tos, oop value,
3276
int offset) {
3277
*((oop *)&tos[Interpreter::expr_index_at(-offset)]) = value;
3278
}
3279
3280
// needs to be platform dep for the 32 bit platforms.
3281
void BytecodeInterpreter::set_stack_double(intptr_t *tos, jdouble value,
3282
int offset) {
3283
((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->d = value;
3284
}
3285
3286
void BytecodeInterpreter::set_stack_double_from_addr(intptr_t *tos,
3287
address addr, int offset) {
3288
(((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->d =
3289
((VMJavaVal64*)addr)->d);
3290
}
3291
3292
void BytecodeInterpreter::set_stack_long(intptr_t *tos, jlong value,
3293
int offset) {
3294
((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset+1)])->l = 0xdeedbeeb;
3295
((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->l = value;
3296
}
3297
3298
void BytecodeInterpreter::set_stack_long_from_addr(intptr_t *tos,
3299
address addr, int offset) {
3300
((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset+1)])->l = 0xdeedbeeb;
3301
((VMJavaVal64*)&tos[Interpreter::expr_index_at(-offset)])->l =
3302
((VMJavaVal64*)addr)->l;
3303
}
3304
3305
// Locals
3306
3307
address BytecodeInterpreter::locals_slot(intptr_t* locals, int offset) {
3308
return (address)locals[Interpreter::local_index_at(-offset)];
3309
}
3310
jint BytecodeInterpreter::locals_int(intptr_t* locals, int offset) {
3311
return (jint)locals[Interpreter::local_index_at(-offset)];
3312
}
3313
jfloat BytecodeInterpreter::locals_float(intptr_t* locals, int offset) {
3314
return (jfloat)locals[Interpreter::local_index_at(-offset)];
3315
}
3316
oop BytecodeInterpreter::locals_object(intptr_t* locals, int offset) {
3317
return cast_to_oop(locals[Interpreter::local_index_at(-offset)]);
3318
}
3319
jdouble BytecodeInterpreter::locals_double(intptr_t* locals, int offset) {
3320
return ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->d;
3321
}
3322
jlong BytecodeInterpreter::locals_long(intptr_t* locals, int offset) {
3323
return ((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->l;
3324
}
3325
3326
// Returns the address of locals value.
3327
address BytecodeInterpreter::locals_long_at(intptr_t* locals, int offset) {
3328
return ((address)&locals[Interpreter::local_index_at(-(offset+1))]);
3329
}
3330
address BytecodeInterpreter::locals_double_at(intptr_t* locals, int offset) {
3331
return ((address)&locals[Interpreter::local_index_at(-(offset+1))]);
3332
}
3333
3334
// Used for local value or returnAddress
3335
void BytecodeInterpreter::set_locals_slot(intptr_t *locals,
3336
address value, int offset) {
3337
*((address*)&locals[Interpreter::local_index_at(-offset)]) = value;
3338
}
3339
void BytecodeInterpreter::set_locals_int(intptr_t *locals,
3340
jint value, int offset) {
3341
*((jint *)&locals[Interpreter::local_index_at(-offset)]) = value;
3342
}
3343
void BytecodeInterpreter::set_locals_float(intptr_t *locals,
3344
jfloat value, int offset) {
3345
*((jfloat *)&locals[Interpreter::local_index_at(-offset)]) = value;
3346
}
3347
void BytecodeInterpreter::set_locals_object(intptr_t *locals,
3348
oop value, int offset) {
3349
*((oop *)&locals[Interpreter::local_index_at(-offset)]) = value;
3350
}
3351
void BytecodeInterpreter::set_locals_double(intptr_t *locals,
3352
jdouble value, int offset) {
3353
((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->d = value;
3354
}
3355
void BytecodeInterpreter::set_locals_long(intptr_t *locals,
3356
jlong value, int offset) {
3357
((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->l = value;
3358
}
3359
void BytecodeInterpreter::set_locals_double_from_addr(intptr_t *locals,
3360
address addr, int offset) {
3361
((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->d = ((VMJavaVal64*)addr)->d;
3362
}
3363
void BytecodeInterpreter::set_locals_long_from_addr(intptr_t *locals,
3364
address addr, int offset) {
3365
((VMJavaVal64*)&locals[Interpreter::local_index_at(-(offset+1))])->l = ((VMJavaVal64*)addr)->l;
3366
}
3367
3368
void BytecodeInterpreter::astore(intptr_t* tos, int stack_offset,
3369
intptr_t* locals, int locals_offset) {
3370
intptr_t value = tos[Interpreter::expr_index_at(-stack_offset)];
3371
locals[Interpreter::local_index_at(-locals_offset)] = value;
3372
}
3373
3374
3375
void BytecodeInterpreter::copy_stack_slot(intptr_t *tos, int from_offset,
3376
int to_offset) {
3377
tos[Interpreter::expr_index_at(-to_offset)] =
3378
(intptr_t)tos[Interpreter::expr_index_at(-from_offset)];
3379
}
3380
3381
void BytecodeInterpreter::dup(intptr_t *tos) {
3382
copy_stack_slot(tos, -1, 0);
3383
}
3384
void BytecodeInterpreter::dup2(intptr_t *tos) {
3385
copy_stack_slot(tos, -2, 0);
3386
copy_stack_slot(tos, -1, 1);
3387
}
3388
3389
void BytecodeInterpreter::dup_x1(intptr_t *tos) {
3390
/* insert top word two down */
3391
copy_stack_slot(tos, -1, 0);
3392
copy_stack_slot(tos, -2, -1);
3393
copy_stack_slot(tos, 0, -2);
3394
}
3395
3396
void BytecodeInterpreter::dup_x2(intptr_t *tos) {
3397
/* insert top word three down */
3398
copy_stack_slot(tos, -1, 0);
3399
copy_stack_slot(tos, -2, -1);
3400
copy_stack_slot(tos, -3, -2);
3401
copy_stack_slot(tos, 0, -3);
3402
}
3403
void BytecodeInterpreter::dup2_x1(intptr_t *tos) {
3404
/* insert top 2 slots three down */
3405
copy_stack_slot(tos, -1, 1);
3406
copy_stack_slot(tos, -2, 0);
3407
copy_stack_slot(tos, -3, -1);
3408
copy_stack_slot(tos, 1, -2);
3409
copy_stack_slot(tos, 0, -3);
3410
}
3411
void BytecodeInterpreter::dup2_x2(intptr_t *tos) {
3412
/* insert top 2 slots four down */
3413
copy_stack_slot(tos, -1, 1);
3414
copy_stack_slot(tos, -2, 0);
3415
copy_stack_slot(tos, -3, -1);
3416
copy_stack_slot(tos, -4, -2);
3417
copy_stack_slot(tos, 1, -3);
3418
copy_stack_slot(tos, 0, -4);
3419
}
3420
3421
3422
void BytecodeInterpreter::swap(intptr_t *tos) {
3423
// swap top two elements
3424
intptr_t val = tos[Interpreter::expr_index_at(1)];
3425
// Copy -2 entry to -1
3426
copy_stack_slot(tos, -2, -1);
3427
// Store saved -1 entry into -2
3428
tos[Interpreter::expr_index_at(2)] = val;
3429
}
3430
// --------------------------------------------------------------------------------
3431
// Non-product code
3432
#ifndef PRODUCT
3433
3434
const char* BytecodeInterpreter::C_msg(BytecodeInterpreter::messages msg) {
3435
switch (msg) {
3436
case BytecodeInterpreter::no_request: return("no_request");
3437
case BytecodeInterpreter::initialize: return("initialize");
3438
// status message to C++ interpreter
3439
case BytecodeInterpreter::method_entry: return("method_entry");
3440
case BytecodeInterpreter::method_resume: return("method_resume");
3441
case BytecodeInterpreter::got_monitors: return("got_monitors");
3442
case BytecodeInterpreter::rethrow_exception: return("rethrow_exception");
3443
// requests to frame manager from C++ interpreter
3444
case BytecodeInterpreter::call_method: return("call_method");
3445
case BytecodeInterpreter::return_from_method: return("return_from_method");
3446
case BytecodeInterpreter::more_monitors: return("more_monitors");
3447
case BytecodeInterpreter::throwing_exception: return("throwing_exception");
3448
case BytecodeInterpreter::popping_frame: return("popping_frame");
3449
case BytecodeInterpreter::do_osr: return("do_osr");
3450
// deopt
3451
case BytecodeInterpreter::deopt_resume: return("deopt_resume");
3452
case BytecodeInterpreter::deopt_resume2: return("deopt_resume2");
3453
default: return("BAD MSG");
3454
}
3455
}
3456
void
3457
BytecodeInterpreter::print() {
3458
tty->print_cr("thread: " INTPTR_FORMAT, (uintptr_t) this->_thread);
3459
tty->print_cr("bcp: " INTPTR_FORMAT, (uintptr_t) this->_bcp);
3460
tty->print_cr("locals: " INTPTR_FORMAT, (uintptr_t) this->_locals);
3461
tty->print_cr("constants: " INTPTR_FORMAT, (uintptr_t) this->_constants);
3462
{
3463
ResourceMark rm;
3464
char *method_name = _method->name_and_sig_as_C_string();
3465
tty->print_cr("method: " INTPTR_FORMAT "[ %s ]", (uintptr_t) this->_method, method_name);
3466
}
3467
tty->print_cr("mdx: " INTPTR_FORMAT, (uintptr_t) this->_mdx);
3468
tty->print_cr("stack: " INTPTR_FORMAT, (uintptr_t) this->_stack);
3469
tty->print_cr("msg: %s", C_msg(this->_msg));
3470
tty->print_cr("result_to_call._callee: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee);
3471
tty->print_cr("result_to_call._callee_entry_point: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee_entry_point);
3472
tty->print_cr("result_to_call._bcp_advance: %d ", this->_result._to_call._bcp_advance);
3473
tty->print_cr("osr._osr_buf: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_buf);
3474
tty->print_cr("osr._osr_entry: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_entry);
3475
tty->print_cr("prev_link: " INTPTR_FORMAT, (uintptr_t) this->_prev_link);
3476
tty->print_cr("native_mirror: " INTPTR_FORMAT, (uintptr_t) p2i(this->_oop_temp));
3477
tty->print_cr("stack_base: " INTPTR_FORMAT, (uintptr_t) this->_stack_base);
3478
tty->print_cr("stack_limit: " INTPTR_FORMAT, (uintptr_t) this->_stack_limit);
3479
tty->print_cr("monitor_base: " INTPTR_FORMAT, (uintptr_t) this->_monitor_base);
3480
#ifdef SPARC
3481
tty->print_cr("last_Java_pc: " INTPTR_FORMAT, (uintptr_t) this->_last_Java_pc);
3482
tty->print_cr("frame_bottom: " INTPTR_FORMAT, (uintptr_t) this->_frame_bottom);
3483
tty->print_cr("&native_fresult: " INTPTR_FORMAT, (uintptr_t) &this->_native_fresult);
3484
tty->print_cr("native_lresult: " INTPTR_FORMAT, (uintptr_t) this->_native_lresult);
3485
#endif
3486
#if !defined(ZERO)
3487
tty->print_cr("last_Java_fp: " INTPTR_FORMAT, (uintptr_t) this->_last_Java_fp);
3488
#endif // !ZERO
3489
tty->print_cr("self_link: " INTPTR_FORMAT, (uintptr_t) this->_self_link);
3490
}
3491
3492
extern "C" {
3493
void PI(uintptr_t arg) {
3494
((BytecodeInterpreter*)arg)->print();
3495
}
3496
}
3497
#endif // PRODUCT
3498
3499
#endif // JVMTI
3500
#endif // CC_INTERP
3501
3502