I'm trying to do something like this - copy the top N elements of the stack to an array. I want to use it to define the invokevirtual, invokespecial, invokestatic, invokeinterface, and invokedynamic instructions for a Java Ahead-Of-Time Compiler. The stack is a linked list and __pop() unwinds and returns the top of the stack.
public : void __sipop(){
topframe = topframe->prev;
}
public : void __longpop(){
topframe = topframe->prev->prev;
}
public : jvalue __pop(){
//also shared with bytecode
jvalue value = topframe->value;
if(topframe->type == 'J' || topframe->type == 'D'){
__longpop();
} else{
__sipop();
}
return value;
}
public : jvalue* __extract(int count){
jvalue extracted [count];
for(int i = 0; i < count; i++){
extracted[count - i - 1] = __pop();
}
return extracted;
}
Will my implementation crash at runtime?