13.10.2014 Views

OPTIMIZING THE JAVA VIRTUAL MACHINE INSTRUCTION SET BY ...

OPTIMIZING THE JAVA VIRTUAL MACHINE INSTRUCTION SET BY ...

OPTIMIZING THE JAVA VIRTUAL MACHINE INSTRUCTION SET BY ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

29<br />

execute (JMethod * method, Slot * callingStack, int callingTop) // 1<br />

{ // 2<br />

Slot * stack = new slot (method.maxStack()) // 3<br />

Slot * locals = new Slot (method.maxLocals()) // 4<br />

// 5<br />

int nps = method.numParamSlots(); // 6<br />

for (int i = 0; i < nps; i++) // 7<br />

{ // 8<br />

locals[i] = callingStack[callingTop-nps+1+i]; // 9<br />

} // 10<br />

// 11<br />

ConstantPool *cp = method.constantPool(); // 12<br />

u1* code = method.code(); // 13<br />

SlotPos pc = 0; // 14<br />

SlotPos npc = 0; // 15<br />

// 16<br />

FDE_LOOP: // 17<br />

pc = npc; // 18<br />

npc += InstructionSize[code[pc]]; // 19<br />

switch (code[pc]) { // 20<br />

... // 21<br />

case op_iload_1: // 22<br />

top++; // 23<br />

stack[top] = locals[1]; // 24<br />

goto FDE_LOOP: // 25<br />

... // 26<br />

case op_iconst_1: // 27<br />

top++; // 28<br />

stack[top] = 1; // 29<br />

goto FDE_LOOP: // 30<br />

... // 31<br />

} // 32<br />

} // 33<br />

Figure 2.10: Implementation of a Simple Virtual Machine<br />

2.6 Implementing a Simple Java Interpreter<br />

This section examines the implementation of a simple Java interpreter. It shows how<br />

the virtual machine’s core data structures interact with the interpreter’s execution<br />

loop. The implementation is shown in low level C-like pseudo code. Some type casts<br />

that would be necessary in a C language implementation have been omitted in order<br />

to improve the clarity of the figure.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!