What is the pattern for such assignment in bytecode?

Hi,

I wish to identify the assignment pattern in the bytecode, which corresponds to the language level: variable = method_invocation; where variable may be a local, or field. Is it always safe to say the following?

This pattern is: the invokevirtual/invokeinterface..., immediately folllowed by putfield/astore ...

Is it possible for different compilers to generate different bytecode for such assignment statements? Thank you very much!

-- Sunny

[477 byte] By [Sunny_Daya] at [2007-10-3 6:08:23]
# 1

Probably only for the very simplest of assignments, eg.

int a = getInt();

But I imagine more complicated assignments such as

int a, b;

a = b = getInt();

myClass.a = getInt();

a = anotherRef.getInt();

could complicate matters.

You cannot always assume that other programmers will only ever use the same programming constructs as yourself.

regards,

Owen

omcgoverna at 2007-7-15 0:51:27 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Hi Owen,

Thank you for your example. So one set of bytecode (eg, virtualinvoke followed by putfield) could correspond to several phenomenon (different statements) in java source level and vice versa - one jave source level code could be translated into different bytecode by different compilers. Is that right?

Nice day,

-- Sunny

Sunny_Daya at 2007-7-15 0:51:27 > top of Java-index,Java HotSpot Virtual Machine,Specifications...