From: Arno P. <ar...@pu...> - 2009-12-16 13:01:27
|
Sometimes the compiler will generate a pop2 byte code instruction. The documentation says that it will remove either one long or double element, or two integers (the spec refers to these as computational types 1 and 2). In XMLVM, we have a union called XMLVMElem that represents the union of all data types that can be pushed onto the stack. The sizeof(XMLVMElem) therefore corresponds to a computational type 2. This makes it difficult to implement pop2 since we need to know if the top of the stack is of computational type 1 or 2. We don't do a data flow analysis and therefore we don't know. As a consequence, we cannot implement pop2. Here are two situations where the compiler can generate the pop2 instruction: // Example 1 long foo() { return 42; } void bar() { foo(); } Since bar() does not make use of the long return value, the compiler will generate the pop2 instruction to clean up the stack. // Example 2 int foo() { return 42; } void bar() { foo(); foo(); } Here a good-optimizing compiler will do one pop2 instruction after the second call to foo(). We are currently working on a conversion from stack- to register-based instructions which will also take care of this problem. What can you do in the meantime to avoid the pop2-problem? Luckily the answer is simple: assign the return value to a local variable: void bar() { long ret = foo(); } For good optimizing compilers it might notice the unused local variable and might still generate the pop2 instruction. In this case make 'ret' an instance variable. Arno |