argument of invokevirtual
  Home FAQ Contact Sign in
comp.lang.java.machine only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.java.machine Profile…
 Up
argument of invokevirtual         


Author: Toby Kim
Date: Aug 22, 2006 06:57

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?

The code snippet (1) is compiled into the bytecode (2).
Neither printStackTrace() nor equals() are not 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);
Show full article (0.97Kb)
2 Comments
Re: argument of invokevirtual         


Author: Thomas Hawtin
Date: Aug 22, 2006 09:09

Toby Kim wrote:
> 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?
>
> The code snippet (1) is compiled into the bytecode (2).
> Neither printStackTrace() nor equals() are not 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 is not important. Indeed binary
compatibility requires that a method may be moved to a super class.
Show full article (1.13Kb)
no comments
Re: argument of invokevirtual         


Author: Chris Uppal
Date: Aug 22, 2006 08:25

Toby Kim wrote:
> 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?

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.
Show full article (1.35Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
Re: Creationist Argument: Argument by Undeclared Variabletalk.origins ·