Definition of the JVM registers for this real machine implementation, namely, the stack area and program counter. There are a significant number of macros available for navigating push-up stack area, the stack pointer, and stack frame.
Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
Licensed under the Apache License, Version 2.0 ("the License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
Definition in file jvmreg.h.
Go to the source code of this file.
Data Structures | ||||||||||||||||||||||||||||
struct | jvm_pc | |||||||||||||||||||||||||||
Program counter. More... | ||||||||||||||||||||||||||||
Navigate stack frame in depth. | ||||||||||||||||||||||||||||
Use these macros to iteratively point up and down the stack from from current fram to bottom of the stack.
| ||||||||||||||||||||||||||||
#define | CHECK_FINAL_STACK_FRAME(thridx) CHECK_FINAL_STACK_FRAME_GENERIC(thridx, GET_FP(thridx)) | |||||||||||||||||||||||||||
#define | CHECK_FINAL_STACK_FRAME_GENERIC(thridx, some_fp) | |||||||||||||||||||||||||||
#define | CHECK_FINAL_STACK_FRAME_ULTIMATE(thridx) (JVMCFG_NULL_SP == GET_FP(thridx)) | |||||||||||||||||||||||||||
#define | FIRST_STACK_FRAME(thridx) GET_FP(thridx) | |||||||||||||||||||||||||||
#define | NEXT_STACK_FRAME(thridx) NEXT_STACK_FRAME_GENERIC(thridx, GET_FP(thridx)) | |||||||||||||||||||||||||||
#define | NEXT_STACK_FRAME_GENERIC(thridx, some_fp) STACK(thridx, some_fp + JVMREG_STACK_FP_OFFSET) | |||||||||||||||||||||||||||
Move the stack pointer up and down. | ||||||||||||||||||||||||||||
Increment/decrement SP (N/A to frame pointer).
It is safe to reference SP in the
| ||||||||||||||||||||||||||||
#define | DEC_SP(thridx, value) THREAD(thridx).sp -= (value) | |||||||||||||||||||||||||||
#define | INC_SP(thridx, value) THREAD(thridx).sp += (value) | |||||||||||||||||||||||||||
Navigate the code area of of the current method. | ||||||||||||||||||||||||||||
Calculate pointers to several important real machine addresses in the class file of the current method of a specific thread:
| ||||||||||||||||||||||||||||
#define | DEREFERENCE_PC_CODE_ATTRIBUTE(thridx) | |||||||||||||||||||||||||||
Code_attribute in method table for current program counter on a given thread. | ||||||||||||||||||||||||||||
#define | DEREFERENCE_PC_CODE_BASE(thridx) (DEREFERENCE_PC_CODE_ATTRIBUTE(thridx)->code) | |||||||||||||||||||||||||||
Real address of first opcode of this method in current program counter on a given thread. | ||||||||||||||||||||||||||||
#define | DEREFERENCE_PC_CODE_CURRENT_OPCODE(thridx) (&DEREFERENCE_PC_CODE_BASE(thridx)[THIS_PC(thridx)->offset]) | |||||||||||||||||||||||||||
Real address of first opcode of this method in current program counter on a given thread. | ||||||||||||||||||||||||||||
#define | DEREFERENCE_PC_EXCEPTION_TABLE(thridx) (DEREFERENCE_PC_CODE_ATTRIBUTE(thridx)->exception_table) | |||||||||||||||||||||||||||
Real address of exception table of this method in current program counter on a given thread. | ||||||||||||||||||||||||||||
#define | DEREFERENCE_PC_EXCEPTIONS_ATTRIBUTE(thridx) | |||||||||||||||||||||||||||
Exceptions_attribute in method table for current program counter on a given thread. | ||||||||||||||||||||||||||||
#define | DEREFERENCE_PC_GENERIC_ATTRIBUTE(thridx, pc_member) | |||||||||||||||||||||||||||
Untyped attribute in method table for current program counter on a given thread. | ||||||||||||||||||||||||||||
#define | THIS_PC(thridx) (&THREAD(thridx).pc) | |||||||||||||||||||||||||||
Locate program counter for a given thread. | ||||||||||||||||||||||||||||
#define | THIS_PCFS(thridx) (CLASS_OBJECT_LINKAGE(THIS_PC(thridx)->clsidx)->pcfs) | |||||||||||||||||||||||||||
Locate ClassFile for current program counter on a given thread. | ||||||||||||||||||||||||||||
Reading and writing to the stack pointer. | ||||||||||||||||||||||||||||
Load/store values from/to the frame pointer.
| ||||||||||||||||||||||||||||
#define | GET_FP(thridx) (THREAD(thridx).fp) | |||||||||||||||||||||||||||
#define | PUT_FP_IMMEDIATE(thridx, value) THREAD(thridx).fp = (value) | |||||||||||||||||||||||||||
Access the stack frame. | ||||||||||||||||||||||||||||
Read and write (jint) values from and to the current stack frame. Accesses are always as (jint), casting is performed outside of these macros.
| ||||||||||||||||||||||||||||
#define | GET_LOCAL_VAR(thridx, frmidx) ((jint) (STACK(thridx, GET_FP(thridx) - frmidx))) | |||||||||||||||||||||||||||
Read a local variable from the stack frame. | ||||||||||||||||||||||||||||
#define | GET_TYPED_LOCAL_VAR(thridx, frmidx, cast) ((cast) GET_LOCAL_VAR(thridx, frmidx))) | |||||||||||||||||||||||||||
Cast a GET_LOCAL_VAR() as any arbitrary data type. | ||||||||||||||||||||||||||||
#define | JINT_ADDRESS_LOCAL_VAR(thridx, frmidx) ((jint *) &STACK(thridx, GET_FP(thridx) - frmidx)) | |||||||||||||||||||||||||||
Real machine address of a local variable in the stack frame. | ||||||||||||||||||||||||||||
#define | PUT_LOCAL_VAR(thridx, frmidx, value) *JINT_ADDRESS_LOCAL_VAR(thridx, frmidx) = (jint) (value) | |||||||||||||||||||||||||||
Write a local variable from the stack frame. | ||||||||||||||||||||||||||||
Macros for manipulating program counter. | ||||||||||||||||||||||||||||
load the program counter and store its contents from/to an arbitrary location, from/to the stack, and load with an immediate value.
| ||||||||||||||||||||||||||||
#define | GET_PC(_thridx, _target) | |||||||||||||||||||||||||||
#define | GET_PC_FIELD(_thridx, _target, _field) _target = GET_PC_FIELD_IMMEDIATE(_thridx, _field) | |||||||||||||||||||||||||||
#define | GET_PC_FIELD_IMMEDIATE(_thridx, _field) THREAD(_thridx).pc._field | |||||||||||||||||||||||||||
#define | POP_PC(_thridx) | |||||||||||||||||||||||||||
#define | PUSH_PC(_thridx) | |||||||||||||||||||||||||||
#define | PUT_PC(_thridx, _source) | |||||||||||||||||||||||||||
#define | PUT_PC_IMMEDIATE(_thridx,_clsidx,_mthidx,_codeatridx,_excpatridx,_offset) | |||||||||||||||||||||||||||
Reading and writing to the stack pointer. | ||||||||||||||||||||||||||||
Load/store values from/to the stack pointer itself, not stack memory it points to.
| ||||||||||||||||||||||||||||
#define | GET_SP(thridx) (THREAD(thridx).sp) | |||||||||||||||||||||||||||
#define | PUT_SP_IMMEDIATE(thridx, value) THREAD(thridx).sp = value | |||||||||||||||||||||||||||
Reading and writing into the stack area. | ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
#define | GET_SP_WORD(thridx, idx, cast) ((cast) (STACK(thridx, GET_SP(thridx) - idx))) | |||||||||||||||||||||||||||
Read a word at given depth in stack. | ||||||||||||||||||||||||||||
#define | PUT_SP_WORD(thridx, idx, value) STACK(thridx, GET_SP(thridx) - idx) = (jint) (value) | |||||||||||||||||||||||||||
Write a word at given depth in stack. | ||||||||||||||||||||||||||||
Locate position in stack frame of its components. | ||||||||||||||||||||||||||||
Locate the local storage size, garbage collection pointer, old frame pointer, and start of local storage area. The current frame pointer always points to the first word of the local storage area of the stack frame.
| ||||||||||||||||||||||||||||
#define | JVMREG_FRAME_CURRENT_LOCAL_STORAGE_SIZE(thridx) (GET_FP(thridx) + JVMREG_STACK_LS_OFFSET) | |||||||||||||||||||||||||||
#define | JVMREG_FRAME_CURRENT_SCRATCH_AREA(thridx) GET_FP(thridx) | |||||||||||||||||||||||||||
#define | JVMREG_FRAME_GC(thridx) (GET_FP(thridx) + JVMREG_STACK_GC_OFFSET) | |||||||||||||||||||||||||||
#define | JVMREG_FRAME_PREVIOUS_FP(thridx) (GET_FP(thridx) + JVMREG_STACK_FP_OFFSET) | |||||||||||||||||||||||||||
Stack frame geometry. | ||||||||||||||||||||||||||||
Frame height = PC + GC + FP + max_locals (from code atr) + SA (aka max_stack, SA being scratch area, the operand stack). Minimum will be a zero-sized max_locals plus current SA. | ||||||||||||||||||||||||||||
#define | JVMREG_STACK_FP_HEIGHT 1 | |||||||||||||||||||||||||||
#define | JVMREG_STACK_FP_OFFSET | |||||||||||||||||||||||||||
#define | JVMREG_STACK_GC_HEIGHT 1 | |||||||||||||||||||||||||||
#define | JVMREG_STACK_GC_OFFSET | |||||||||||||||||||||||||||
#define | JVMREG_STACK_LS_HEIGHT 1 | |||||||||||||||||||||||||||
#define | JVMREG_STACK_LS_OFFSET JVMREG_STACK_LS_HEIGHT | |||||||||||||||||||||||||||
#define | JVMREG_STACK_MIN_FRAME_HEIGHT | |||||||||||||||||||||||||||
#define | JVMREG_STACK_PC_HEIGHT 5 | |||||||||||||||||||||||||||
#define | JVMREG_STACK_PC_OFFSET | |||||||||||||||||||||||||||
Location of the old program counter in the current stack frame. | ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
#define | JVMREG_STACK_PC_CLSIDX_OFFSET JVMREG_STACK_PC_OFFSET - 0 | |||||||||||||||||||||||||||
#define | JVMREG_STACK_PC_CODEATRIDX_OFFSET JVMREG_STACK_PC_OFFSET - 2 | |||||||||||||||||||||||||||
#define | JVMREG_STACK_PC_EXCPATRIDX_OFFSET JVMREG_STACK_PC_OFFSET - 3 | |||||||||||||||||||||||||||
#define | JVMREG_STACK_PC_MTHIDX_OFFSET JVMREG_STACK_PC_OFFSET - 1 | |||||||||||||||||||||||||||
#define | JVMREG_STACK_PC_OFFSET_OFFSET JVMREG_STACK_PC_OFFSET - 4 | |||||||||||||||||||||||||||
Stack push and pop for any 32-bit data type. | ||||||||||||||||||||||||||||
Push/pop item to/from stack (MUST be integer size!).
| ||||||||||||||||||||||||||||
#define | POP(thridx, item, cast) | |||||||||||||||||||||||||||
#define | PUSH(thridx, item) | |||||||||||||||||||||||||||
Stack push and pop of frame pointer. | ||||||||||||||||||||||||||||
Push/pop FP to/from stack.
| ||||||||||||||||||||||||||||
#define | POP_FP(thridx) POP(thridx, THREAD(thridx).fp, jvm_sp) | |||||||||||||||||||||||||||
#define | PUSH_FP(thridx) PUSH(thridx, THREAD(thridx).fp) | |||||||||||||||||||||||||||
Geometry of a complete stack frame. | ||||||||||||||||||||||||||||
A complete stack frame is pushed every time a JVM virtual method is called, where old program counter and old stack state must be saved and a new one created on top of it. The macro PUSH_FRAME() is designed for this use. For example, here is an existing stack frame:
SP --> [scratch] (operand stack, >= 0 words) ... higher address ... ... [scratch] ... [top of previous frame] ... FP -> [locals of previous frame] ... lower address During PUSH_FRAME(n), there are an words of local storage allocated for JVM method scratch area, where n >= 0, up to the maximum stack size less the top few words:
new SP --> [PC of next JVM instruction] ... high address [old FP] ... [GC pointer for this NEW frame] ... [value 'n', size of LS (local storage) area beneath] new FP --> [local 0] ... [local 1] ... [local 2] ... ... ... [local n-1] ... --- end of NEW frame --- old SP -> [scratch] (same data shown above) ... ... ... [scratch] ... [top of previous frame] ... old FP -> [locals of previous frame] ... low address --- end of OLD frame --- POP_FRAME() does the reverse or PUSH_FRAME and removes the top stack frame. The final POP_FRAME() will have a stored (old) frame pointer containing JVMCFG_NULL_SP, so when this frame is popped, opcode_run() will detect that this thread has finished running.
| ||||||||||||||||||||||||||||
#define | POP_FRAME(thridx) | |||||||||||||||||||||||||||
#define | PUSH_FRAME(thridx, locals) | |||||||||||||||||||||||||||
Stack push and pop of garbage collection pointer. | ||||||||||||||||||||||||||||
Push/pop GC pointer to/from stack. Due to the potential for multiple GC implementations in this JVM, the GC pointer here is not related to any one of them. Instead, it is cast here as a simple rvoid pointer so as to support all of them.
| ||||||||||||||||||||||||||||
#define | POP_GC(thridx) | |||||||||||||||||||||||||||
#define | PUSH_GC(thridx, num_locals) | |||||||||||||||||||||||||||
Push and pop of local variables. | ||||||||||||||||||||||||||||
Add/remove empty space for local storage to/from stack.
| ||||||||||||||||||||||||||||
#define | POP_LOCAL(thridx, items) DEC_SP(thridx, items) | |||||||||||||||||||||||||||
#define | PUSH_LOCAL(thridx, items) INC_SP(thridx, items) | |||||||||||||||||||||||||||
Two types of exception tables. | ||||||||||||||||||||||||||||
The JVM exception index table (defined by Exceptions attribute) and JVM exception table (defined inside Code attribute) are both simple offsets into their respective tables. Both are bound up directly with the program counter, so are defined here. | ||||||||||||||||||||||||||||
typedef u2 | jvm_exception_index_table_index | |||||||||||||||||||||||||||
typedef u2 | jvm_exception_table_index | |||||||||||||||||||||||||||
Defines | ||||||||||||||||||||||||||||
#define | GET_GC(thridx) ((rvoid *) &STACK(thridx, GET_FP(thridx) + JVMREG_STACK_GC_OFFSET)) | |||||||||||||||||||||||||||
Retrieve the stack frame garbage collection pointer. | ||||||||||||||||||||||||||||
#define | STACK(thridx, stkidx) THREAD(thridx).stack[stkidx] | |||||||||||||||||||||||||||
Access structures of stack at certain index. | ||||||||||||||||||||||||||||
Typedefs | ||||||||||||||||||||||||||||
typedef u1 | jvm_virtual_opcode | |||||||||||||||||||||||||||
Functions | ||||||||||||||||||||||||||||
ARCH_COPYRIGHT_APACHE (jvmreg, h,"$URL: https://svn.apache.org/path/name/jvmreg.h $ $Id: jvmreg.h 0 09/28/2005 dlydick $") |
|
Access structures of stack at certain index.
Definition at line 100 of file jvmreg.h. Referenced by jvmutil_print_errtype_stack(), and jvmutil_print_stack_common(). |
|
Each of 5 items takes 1 stack word |
|
Frame pointer takes one word |
|
GC real machine 32-bit ptr takes 1 word |
|
Num local storage words takes 1 word |
|
Value:
|
|
Offsets from current FP of local storage size word |
|
Value: Offsets from current FP of garbage collection pointer |
|
Value: Offsets from current FP of old frame pointer |
|
Value: Offsets from current FP of stack pointer |
|
|
|
|
|
Read a word at given depth in stack.
|
|
Write a word at given depth in stack.
|
|
Definition at line 242 of file jvmreg.h. Referenced by jvmutil_print_errtype_stack(), and jvmutil_print_stack_common(). |
|
|
|
Retrieve the stack frame garbage collection pointer.
|
|
|
|
|
|
Value: INC_SP(thridx, 1); \ PUT_SP_WORD(thridx, 0, (item)) Definition at line 328 of file jvmreg.h. Referenced by native_run_local_return_jdouble(), native_run_local_return_jfloat(), native_run_local_return_jint(), native_run_local_return_jlong(), native_run_local_return_jobject(), and opcode_run(). |
|
Value: item = GET_SP_WORD(thridx, 0, cast); \ DEC_SP(thridx, 1) Definition at line 331 of file jvmreg.h. Referenced by opcode_run(). |
|
|
|
|
|
Value: INC_SP(thridx, JVMREG_STACK_GC_HEIGHT); \ ((rvoid *) \ *(&STACK(thridx, THREAD(thridx).sp - JVMREG_STACK_GC_HEIGHT+1))) =\ GC_STACK_NEW(thridx, num_locals) |
|
Value: GC_STACK_DELETE(thridx, \ ((rvoid **) \ &STACK(thridx, THREAD(thridx).sp - \ JVMREG_STACK_GC_HEIGHT + 1)), \ (&STACK(thridx, THREAD(thridx).sp - \ JVMREG_STACK_GC_HEIGHT + 1 - \ JVMREG_STACK_LS_HEIGHT - 1))); \ DEC_SP(thridx, JVMREG_STACK_GC_HEIGHT) |
|
|
|
|
|
|
|
|
|
|
|
|
|
Value: |
|
Value: THREAD(_thridx).pc.clsidx = (_clsidx); \ THREAD(_thridx).pc.mthidx = (_mthidx); \ THREAD(_thridx).pc.codeatridx = (_codeatridx); \ THREAD(_thridx).pc.excpatridx = (_excpatridx); \ THREAD(_thridx).pc.offset = (_offset) Definition at line 519 of file jvmreg.h. Referenced by object_run_method(), opcode_run(), and thread_init(). |
|
Value: |
|
|
|
|
|
Value: |
|
Value: |
|
Definition at line 564 of file jvmreg.h. Referenced by jvmutil_print_errtype_stack(), and jvmutil_print_stack_common(). |
|
Definition at line 565 of file jvmreg.h. Referenced by jvmutil_print_stack_common(). |
|
|
|
|
|
|
|
Locate program counter for a given thread.
Definition at line 621 of file jvmreg.h. Referenced by opcode_run(). |
|
Locate ClassFile for current program counter on a given thread.
Definition at line 639 of file jvmreg.h. Referenced by opcode_run(). |
|
Value: ((jvm_attribute_index_bad != THIS_PC(thridx)->pc_member) \ ? (&THIS_PCFS(thridx)->methods[THIS_PC(thridx)->mthidx] \ ->attributes[THIS_PC(thridx)->pc_member] \ ->ai) \ : rnull)
|
|
Value: ((Exceptions_attribute *) \ DEREFERENCE_PC_GENERIC_ATTRIBUTE(thridx, excpatridx))
|
|
Value: ((Code_attribute *) \ DEREFERENCE_PC_GENERIC_ATTRIBUTE(thridx, codeatridx))
|
|
Real address of exception table of this method in current program counter on a given thread.
|
|
Real address of first opcode of this method in current program counter on a given thread.
Definition at line 747 of file jvmreg.h. Referenced by opcode_run(). |
|
Real address of first opcode of this method in current program counter on a given thread.
|
|
Value: PUSH_LOCAL(thridx, (locals)); \ PUSH(thridx, (locals)); \ PUSH_GC(thridx, (locals)); \ PUSH_FP(thridx); \ PUT_FP_IMMEDIATE(thridx, \ GET_SP(thridx) - JVMREG_STACK_MIN_FRAME_HEIGHT); \ PUSH_PC(thridx); Definition at line 840 of file jvmreg.h. Referenced by object_run_method(), and opcode_run(). |
|
Value: POP_PC(thridx); \ POP_FP(thridx); \ POP_GC(thridx); \ POP_LOCAL(thridx, (1 + GET_SP_WORD(thridx, 0, jint))); Definition at line 849 of file jvmreg.h. Referenced by opcode_run(). |
|
Read a local variable from the stack frame.
|
|
Cast a GET_LOCAL_VAR() as any arbitrary data type.
|
|
Real machine address of a local variable in the stack frame.
|
|
Write a local variable from the stack frame.
|
|
Definition at line 982 of file jvmreg.h. Referenced by jlThread_isAlive(), and jvmutil_print_stack_common(). |
|
Value: ((JVMCFG_NULL_SP == NEXT_STACK_FRAME_GENERIC(thridx, some_fp)) \ ? rtrue \ : rfalse)
Definition at line 990 of file jvmreg.h. Referenced by jlThread_isAlive(), and jvmutil_print_stack_common(). |
|
Definition at line 995 of file jvmreg.h. Referenced by jlThread_isAlive(), and jvmutil_print_stack_common(). |
|
|
|
|
|
Definition at line 1003 of file jvmreg.h. Referenced by opcode_run(). |
|
The JVM's virtual operation codes are defined as single bytes. This type definition is used to address them. |
|
|
|
|
|
|