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