argument of invokevirtual
3 Message(s) by 3 Author(s) originally posted in java machine
| From: Toby Kim |
Date: Tuesday, August 22, 2006
|
Hi.
While I'm writing
code s on call
graph construction of JAVA programs,
I have got a question.
I'm wondering how the
class name in the
argument of invokevirtual is
determined.
Is it the name of a class containing the
method definition?
The code snippet (1) is compiled into the bytecode (2).
Neither printStackTrace() nor equals() aren't defined in the
AWTException.
But the class name of the first invokevirtual is AWTException,
whereas the class name of the second invokevirtual is Object. Why is
that?
I'd appreciate it if you'd let me know how the class name of
invokevirtual is determined.
(1)
JAVA.awt.AWTException e1 = new JAVA.awt.AWTException("1");
JAVA.awt.AWTException e2 = new JAVA.awt.AWTException("2");
e1.printStackTrace();
e1.equals(e2);
(2)
aload_1
invokevirtual #6; //Method JAVA/awt/AWTException.printStackTrace:()V
aload_1
aload_2
invokevirtual #7; //Method
JAVA/lang/Object.equals:(LJAVA/lang/Object;)ZThanks.
Regards,
Toby Kim
| From: Chris Uppal |
Date: Tuesday, August 22, 2006
|
wrote in message:
While I'm writing codes on call graph construction of JAVA programs,
I have got a question.
I'm wondering how the class name in the argument of invokevirtual is
determined.
Is it the name of a class containing the method definition?
Not usually, at least not for JAVA compiled by a
compiler which obeys the JLS
(there are other sources of
legal bytecode, of course). The full rules are set
out in section 13.1 of the JLS (part of the
binary compatibility stuff).
Ignoring various complications, the rule is that the class name is the name of
the
type of the
expression whose value is the
target of the method invocation
(any kind of method invocation). That is /unless/ the method is one of the
methods defined by Object, in which case the class name is required to be
Object.
So in your example, if you had declared your two variables to have type
JAVA.lang.Exception then the invokevirtual'd invoke JAVA/lang/Exception
printStackTrace()V. If you had declared e1 as a JAVA.lang.Throwable then the
invokevirtual'd name that class instead. OTOH,
equals:(LJAVA/lang/Object;)Z is defined by Object, so any invocation of that
method must name JAVA/lang/Object.
I've, by the way, no idea at all what benefit there is supposed to be in
making JAVA.lang.Object a special case. I suspect there is none...
-- chris
| From: Thomas Hawtin |
Date: Tuesday, August 22, 2006
|
wrote in message:
While I'm writing codes on call graph construction of JAVA programs,
I have got a question.
I'm wondering how the class name in the argument of invokevirtual is
determined.
Is it the name of a class containing the method definition?
The code snippet (1) is compiled into the bytecode (2).
Neither printStackTrace() nor equals() aren't defined in the
AWTException.
But the class name of the first invokevirtual is AWTException,
whereas the class name of the second invokevirtual is Object. Why is
that?
The
parameter and return types must always match. Working out which
overloaded method to use is done at compile time. In 1.5+, the compiler
synthesises bridge methods for covariant return types.
Which class the method is declared on isn't important. Indeed binary
compatibility requires that a method may be moved to a super class.
For methods declared in interfaces, it is preferable to use a class type
if possible because dispatch on a class type is often faster than on an
interface type.
Tom Hawtin
--
Unemployed
English JAVA programmer
http://jroller.com/page/tackline/
Next Message: Exception in thread "CompilerThread0" JAVA.lang.OutOfMemoryError
Blogs related to argument of invokevirtual
A Bridge Too Far
So in this scenario what happens at runtime and how does
Java enforce type
... 4:
invokevirtual #3; //Method
java/io/PrintStream.println:(Ljava/lang/Object;)V
... methods would you choose when faced with an
argument of type Integer?
...
Invokedynamic
It could potentially host C#, or
Java, or Oberon or Ada or Modula-3 just fine.
... Basically, it will be a lot like
invokevirtual (if you don’t know what
... the types of the
arguments be known to match the signature of that method.
...
基础:全面保护你的Java程序安全(上)
第一部分:
Java的安全基础——虚拟机和字节码安全概论:安全问题对很多数人来说都非常 重要。从其历史看,
Java安全主要
... 29
invokevirtual #11 32 return 上面的代码包含 了main()函数的反编译输出。
... Incompatible object
argument for function call
...
argument of invokevirtual
comp.lang.
java.machine:
argument of invokevirtual.
argument of invokevirtual
Hi. While I'm writing codes on call graph construction of
Java programs, I've got a question. I'm wondering how the class name in the
argument of invokevirtual is determined. Is it the name of a class containing the method definition?
...
Automatic Overriding of Parameterized Methods in Java 5
Main2.
java:23: compareAgainst(Main2) in CompareAgainst cannot be applied to (
java.lang.
... 5:
invokevirtual #9; //Method compareAgainst:(LMain2;)I
... casts the
argument to a Main2, and then calls our compareAgainst(Main2) method.
...