Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/interpreter/zero/bytecodeInterpreter.hpp
40957 views
1
/*
2
* Copyright (c) 2002, 2020, 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
#ifndef SHARE_INTERPRETER_BYTECODEINTERPRETER_HPP
26
#define SHARE_INTERPRETER_BYTECODEINTERPRETER_HPP
27
28
#include "memory/allocation.hpp"
29
#include "oops/method.hpp"
30
#include "runtime/basicLock.hpp"
31
#include "runtime/frame.hpp"
32
#include "runtime/globals.hpp"
33
#include "utilities/globalDefinitions.hpp"
34
#include "utilities/macros.hpp"
35
36
// JavaStack Implementation
37
#define MORE_STACK(count) \
38
(topOfStack -= ((count) * Interpreter::stackElementWords))
39
40
// CVM definitions find hotspot equivalents...
41
42
class InterpreterMacroAssembler;
43
44
union VMJavaVal64 {
45
jlong l;
46
jdouble d;
47
uint32_t v[2];
48
};
49
50
51
typedef class BytecodeInterpreter* interpreterState;
52
53
struct call_message {
54
class Method* _callee; // method to call during call_method request
55
address _callee_entry_point; // address to jump to for call_method request
56
int _bcp_advance; // size of the invoke bytecode operation
57
};
58
59
struct osr_message {
60
address _osr_buf; // the osr buffer
61
address _osr_entry; // the entry to the osr method
62
};
63
64
struct osr_result {
65
nmethod* nm; // osr nmethod
66
address return_addr; // osr blob return address
67
};
68
69
// Result returned to frame manager
70
union frame_manager_message {
71
call_message _to_call; // describes callee
72
osr_message _osr; // describes the osr
73
osr_result _osr_result; // result of OSR request
74
};
75
76
class BytecodeInterpreter : StackObj {
77
friend class SharedRuntime;
78
friend class AbstractInterpreterGenerator;
79
friend class ZeroInterpreterGenerator;
80
friend class InterpreterMacroAssembler;
81
friend class frame;
82
friend class VMStructs;
83
84
public:
85
enum messages {
86
no_request = 0, // unused
87
initialize, // Perform one time interpreter initializations (assumes all switches set)
88
// status message to C++ interpreter
89
method_entry, // initial method entry to interpreter
90
method_resume, // frame manager response to return_from_method request (assuming a frame to resume)
91
deopt_resume, // returning from a native call into a deopted frame
92
deopt_resume2, // deopt resume as a result of a PopFrame
93
got_monitors, // frame manager response to more_monitors request
94
rethrow_exception, // unwinding and throwing exception
95
// requests to frame manager from C++ interpreter
96
call_method, // request for new frame from interpreter, manager responds with method_entry
97
return_from_method, // request from interpreter to unwind, manager responds with method_continue
98
more_monitors, // need a new monitor
99
throwing_exception, // unwind stack and rethrow
100
popping_frame, // unwind call and retry call
101
do_osr, // request this invocation be OSR's
102
early_return // early return as commanded by jvmti
103
};
104
105
private:
106
JavaThread* _thread; // the vm's java thread pointer
107
address _bcp; // instruction pointer
108
intptr_t* _locals; // local variable pointer
109
ConstantPoolCache* _constants; // constant pool cache
110
Method* _method; // method being executed
111
oop _mirror; // mirror to klass containing method
112
intptr_t* _stack; // expression stack
113
messages _msg; // frame manager <-> interpreter message
114
frame_manager_message _result; // result to frame manager
115
interpreterState _prev_link; // previous interpreter state
116
oop _oop_temp; // mirror for interpreted native, null otherwise
117
intptr_t* _stack_base; // base of expression stack
118
intptr_t* _stack_limit; // limit of expression stack
119
BasicObjectLock* _monitor_base; // base of monitors on the native stack
120
121
122
public:
123
// Constructor is only used by the initialization step. All other instances are created
124
// by the frame manager.
125
BytecodeInterpreter(messages msg);
126
127
//
128
// Deoptimization support
129
//
130
static void layout_interpreterState(interpreterState to_fill,
131
frame* caller,
132
frame* interpreter_frame,
133
Method* method,
134
intptr_t* locals,
135
intptr_t* stack,
136
intptr_t* stack_base,
137
intptr_t* monitor_base,
138
intptr_t* frame_bottom,
139
bool top_frame);
140
141
/*
142
* Generic 32-bit wide "Java slot" definition. This type occurs
143
* in operand stacks, Java locals, object fields, constant pools.
144
*/
145
union VMJavaVal32 {
146
jint i;
147
jfloat f;
148
class oopDesc* r;
149
uint32_t raw;
150
};
151
152
/*
153
* Generic 64-bit Java value definition
154
*/
155
union VMJavaVal64 {
156
jlong l;
157
jdouble d;
158
uint32_t v[2];
159
};
160
161
/*
162
* Generic 32-bit wide "Java slot" definition. This type occurs
163
* in Java locals, object fields, constant pools, and
164
* operand stacks (as a CVMStackVal32).
165
*/
166
typedef union VMSlotVal32 {
167
VMJavaVal32 j; /* For "Java" values */
168
address a; /* a return created by jsr or jsr_w */
169
} VMSlotVal32;
170
171
172
/*
173
* Generic 32-bit wide stack slot definition.
174
*/
175
union VMStackVal32 {
176
VMJavaVal32 j; /* For "Java" values */
177
VMSlotVal32 s; /* any value from a "slot" or locals[] */
178
};
179
180
inline JavaThread* thread() { return _thread; }
181
182
inline address bcp() { return _bcp; }
183
inline void set_bcp(address new_bcp) { _bcp = new_bcp; }
184
185
inline intptr_t* locals() { return _locals; }
186
187
inline ConstantPoolCache* constants() { return _constants; }
188
inline Method* method() { return _method; }
189
190
inline messages msg() { return _msg; }
191
inline void set_msg(messages new_msg) { _msg = new_msg; }
192
193
inline Method* callee() { return _result._to_call._callee; }
194
inline void set_callee(Method* new_callee) { _result._to_call._callee = new_callee; }
195
inline void set_callee_entry_point(address entry) { _result._to_call._callee_entry_point = entry; }
196
inline void set_osr_buf(address buf) { _result._osr._osr_buf = buf; }
197
inline void set_osr_entry(address entry) { _result._osr._osr_entry = entry; }
198
inline int bcp_advance() { return _result._to_call._bcp_advance; }
199
inline void set_bcp_advance(int count) { _result._to_call._bcp_advance = count; }
200
201
inline interpreterState prev() { return _prev_link; }
202
203
inline intptr_t* stack() { return _stack; }
204
inline void set_stack(intptr_t* new_stack) { _stack = new_stack; }
205
206
207
inline intptr_t* stack_base() { return _stack_base; }
208
inline intptr_t* stack_limit() { return _stack_limit; }
209
210
inline BasicObjectLock* monitor_base() { return _monitor_base; }
211
212
/*
213
* 64-bit Arithmetic:
214
*
215
* The functions below follow the semantics of the
216
* ladd, land, ldiv, lmul, lor, lxor, and lrem bytecodes,
217
* respectively.
218
*/
219
220
static jlong VMlongAdd(jlong op1, jlong op2);
221
static jlong VMlongAnd(jlong op1, jlong op2);
222
static jlong VMlongDiv(jlong op1, jlong op2);
223
static jlong VMlongMul(jlong op1, jlong op2);
224
static jlong VMlongOr (jlong op1, jlong op2);
225
static jlong VMlongSub(jlong op1, jlong op2);
226
static jlong VMlongXor(jlong op1, jlong op2);
227
static jlong VMlongRem(jlong op1, jlong op2);
228
229
/*
230
* Shift:
231
*
232
* The functions below follow the semantics of the
233
* lushr, lshl, and lshr bytecodes, respectively.
234
*/
235
236
static jlong VMlongUshr(jlong op1, jint op2);
237
static jlong VMlongShl (jlong op1, jint op2);
238
static jlong VMlongShr (jlong op1, jint op2);
239
240
/*
241
* Unary:
242
*
243
* Return the negation of "op" (-op), according to
244
* the semantics of the lneg bytecode.
245
*/
246
247
static jlong VMlongNeg(jlong op);
248
249
/*
250
* Return the complement of "op" (~op)
251
*/
252
253
static jlong VMlongNot(jlong op);
254
255
256
/*
257
* Comparisons to 0:
258
*/
259
260
static int32_t VMlongLtz(jlong op); /* op <= 0 */
261
static int32_t VMlongGez(jlong op); /* op >= 0 */
262
static int32_t VMlongEqz(jlong op); /* op == 0 */
263
264
/*
265
* Between operands:
266
*/
267
268
static int32_t VMlongEq(jlong op1, jlong op2); /* op1 == op2 */
269
static int32_t VMlongNe(jlong op1, jlong op2); /* op1 != op2 */
270
static int32_t VMlongGe(jlong op1, jlong op2); /* op1 >= op2 */
271
static int32_t VMlongLe(jlong op1, jlong op2); /* op1 <= op2 */
272
static int32_t VMlongLt(jlong op1, jlong op2); /* op1 < op2 */
273
static int32_t VMlongGt(jlong op1, jlong op2); /* op1 > op2 */
274
275
/*
276
* Comparisons (returning an jint value: 0, 1, or -1)
277
*
278
* Between operands:
279
*
280
* Compare "op1" and "op2" according to the semantics of the
281
* "lcmp" bytecode.
282
*/
283
284
static int32_t VMlongCompare(jlong op1, jlong op2);
285
286
/*
287
* Convert int to long, according to "i2l" bytecode semantics
288
*/
289
static jlong VMint2Long(jint val);
290
291
/*
292
* Convert long to int, according to "l2i" bytecode semantics
293
*/
294
static jint VMlong2Int(jlong val);
295
296
/*
297
* Convert long to float, according to "l2f" bytecode semantics
298
*/
299
static jfloat VMlong2Float(jlong val);
300
301
/*
302
* Convert long to double, according to "l2d" bytecode semantics
303
*/
304
static jdouble VMlong2Double(jlong val);
305
306
/*
307
* Java floating-point float value manipulation.
308
*
309
* The result argument is, once again, an lvalue.
310
*
311
* Arithmetic:
312
*
313
* The functions below follow the semantics of the
314
* fadd, fsub, fmul, fdiv, and frem bytecodes,
315
* respectively.
316
*/
317
318
static jfloat VMfloatAdd(jfloat op1, jfloat op2);
319
static jfloat VMfloatSub(jfloat op1, jfloat op2);
320
static jfloat VMfloatMul(jfloat op1, jfloat op2);
321
static jfloat VMfloatDiv(jfloat op1, jfloat op2);
322
static jfloat VMfloatRem(jfloat op1, jfloat op2);
323
324
/*
325
* Unary:
326
*
327
* Return the negation of "op" (-op), according to
328
* the semantics of the fneg bytecode.
329
*/
330
331
static jfloat VMfloatNeg(jfloat op);
332
333
/*
334
* Comparisons (returning an int value: 0, 1, or -1)
335
*
336
* Between operands:
337
*
338
* Compare "op1" and "op2" according to the semantics of the
339
* "fcmpl" (direction is -1) or "fcmpg" (direction is 1) bytecodes.
340
*/
341
342
static int32_t VMfloatCompare(jfloat op1, jfloat op2,
343
int32_t direction);
344
/*
345
* Conversion:
346
*/
347
348
/*
349
* Convert float to double, according to "f2d" bytecode semantics
350
*/
351
352
static jdouble VMfloat2Double(jfloat op);
353
354
/*
355
******************************************
356
* Java double floating-point manipulation.
357
******************************************
358
*
359
* The result argument is, once again, an lvalue.
360
*
361
* Conversions:
362
*/
363
364
/*
365
* Convert double to int, according to "d2i" bytecode semantics
366
*/
367
368
static jint VMdouble2Int(jdouble val);
369
370
/*
371
* Convert double to float, according to "d2f" bytecode semantics
372
*/
373
374
static jfloat VMdouble2Float(jdouble val);
375
376
/*
377
* Convert int to double, according to "i2d" bytecode semantics
378
*/
379
380
static jdouble VMint2Double(jint val);
381
382
/*
383
* Arithmetic:
384
*
385
* The functions below follow the semantics of the
386
* dadd, dsub, ddiv, dmul, and drem bytecodes, respectively.
387
*/
388
389
static jdouble VMdoubleAdd(jdouble op1, jdouble op2);
390
static jdouble VMdoubleSub(jdouble op1, jdouble op2);
391
static jdouble VMdoubleDiv(jdouble op1, jdouble op2);
392
static jdouble VMdoubleMul(jdouble op1, jdouble op2);
393
static jdouble VMdoubleRem(jdouble op1, jdouble op2);
394
395
/*
396
* Unary:
397
*
398
* Return the negation of "op" (-op), according to
399
* the semantics of the dneg bytecode.
400
*/
401
402
static jdouble VMdoubleNeg(jdouble op);
403
404
/*
405
* Comparisons (returning an int32_t value: 0, 1, or -1)
406
*
407
* Between operands:
408
*
409
* Compare "op1" and "op2" according to the semantics of the
410
* "dcmpl" (direction is -1) or "dcmpg" (direction is 1) bytecodes.
411
*/
412
413
static int32_t VMdoubleCompare(jdouble op1, jdouble op2, int32_t direction);
414
415
/*
416
* Copy two typeless 32-bit words from one location to another.
417
* This is semantically equivalent to:
418
*
419
* to[0] = from[0];
420
* to[1] = from[1];
421
*
422
* but this interface is provided for those platforms that could
423
* optimize this into a single 64-bit transfer.
424
*/
425
426
static void VMmemCopy64(uint32_t to[2], const uint32_t from[2]);
427
428
429
// Arithmetic operations
430
431
/*
432
* Java arithmetic methods.
433
* The functions below follow the semantics of the
434
* iadd, isub, imul, idiv, irem, iand, ior, ixor,
435
* and ineg bytecodes, respectively.
436
*/
437
438
static jint VMintAdd(jint op1, jint op2);
439
static jint VMintSub(jint op1, jint op2);
440
static jint VMintMul(jint op1, jint op2);
441
static jint VMintDiv(jint op1, jint op2);
442
static jint VMintRem(jint op1, jint op2);
443
static jint VMintAnd(jint op1, jint op2);
444
static jint VMintOr (jint op1, jint op2);
445
static jint VMintXor(jint op1, jint op2);
446
447
/*
448
* Shift Operation:
449
* The functions below follow the semantics of the
450
* iushr, ishl, and ishr bytecodes, respectively.
451
*/
452
453
static juint VMintUshr(jint op, jint num);
454
static jint VMintShl (jint op, jint num);
455
static jint VMintShr (jint op, jint num);
456
457
/*
458
* Unary Operation:
459
*
460
* Return the negation of "op" (-op), according to
461
* the semantics of the ineg bytecode.
462
*/
463
464
static jint VMintNeg(jint op);
465
466
/*
467
* Int Conversions:
468
*/
469
470
/*
471
* Convert int to float, according to "i2f" bytecode semantics
472
*/
473
474
static jfloat VMint2Float(jint val);
475
476
/*
477
* Convert int to byte, according to "i2b" bytecode semantics
478
*/
479
480
static jbyte VMint2Byte(jint val);
481
482
/*
483
* Convert int to char, according to "i2c" bytecode semantics
484
*/
485
486
static jchar VMint2Char(jint val);
487
488
/*
489
* Convert int to short, according to "i2s" bytecode semantics
490
*/
491
492
static jshort VMint2Short(jint val);
493
494
/*=========================================================================
495
* Bytecode interpreter operations
496
*=======================================================================*/
497
498
static void dup(intptr_t *tos);
499
static void dup2(intptr_t *tos);
500
static void dup_x1(intptr_t *tos); /* insert top word two down */
501
static void dup_x2(intptr_t *tos); /* insert top word three down */
502
static void dup2_x1(intptr_t *tos); /* insert top 2 slots three down */
503
static void dup2_x2(intptr_t *tos); /* insert top 2 slots four down */
504
static void swap(intptr_t *tos); /* swap top two elements */
505
506
template<bool JVMTI_ENABLED>
507
static void run(interpreterState istate);
508
509
static void astore(intptr_t* topOfStack, int stack_offset,
510
intptr_t* locals, int locals_offset);
511
512
// Support for dup and swap
513
static void copy_stack_slot(intptr_t *tos, int from_offset, int to_offset);
514
515
#ifndef PRODUCT
516
static const char* C_msg(BytecodeInterpreter::messages msg);
517
void print();
518
#endif // PRODUCT
519
520
# include "bytecodeInterpreter_zero.hpp"
521
522
}; // BytecodeInterpreter
523
524
#endif // SHARE_INTERPRETER_BYTECODEINTERPRETER_HPP
525
526