Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Method invocation conversion

Reply
Thread Tools

Re: Method invocation conversion

 
 
=?ISO-8859-1?Q?Daniel_Sj=F6blom?=
Guest
Posts: n/a
 
      11-02-2004
Mark Bottomley wrote:
>
> iload (local variable containing a)
> iload (local variable containing c)
> iadd
> i2b
> istore (local variable containing b)
>
> this guarantees that the range of the addition result is trimmed to be
> in the -128..127 range of a valid byte. The bytecodes that generated
> the parameter for the the method call would compile to something
> that guaranteed the value was in a range for the appropriate integer
> subtype before it got to the method call


But it is not enforced by the VM. There is no guarantee that a byte
passed to a method really is in the byte range, which was the source of
confusion, since it is (depending on how the text is to be interpreted)
mentioned as a structural constraint in the spec. It is ok to pass any
int value to a method taking a byte as argument (in the Sun VMs).

Here is an example demonstrating what I mean (it will happily print any
int value you pass to it):

public class test.ByteTest extends java.lang.Object
{
public void <init>()
{
max stack: 1
max locals: 1

0: aload_0
1: invokespecial java.lang.Object.<init>()
4: return
}

public static void main(java.lang.String[])
{
max stack: 2
max locals: 1

0: aload_0
1: iconst_0
2: aaload
3: invokestatic java.lang.Integer.parseInt(java.lang.String)
6: invokestatic test.ByteTest.method(byte)
9: getstatic java.lang.System.out (java.io.PrintStream)
12: ldc "ok"
14: invokevirtual java.io.PrintStream.println(java.lang.String)
17: return
}

public static void method(byte)
{
max stack: 2
max locals: 1

0: getstatic java.lang.System.out (java.io.PrintStream)
3: iload_0
4: invokevirtual java.io.PrintStream.println(int)
7: return
}
}

--
Daniel Sj÷blom
Remove _NOSPAM to reply by mail
 
Reply With Quote
 
 
 
 
Mark Bottomley
Guest
Posts: n/a
 
      11-02-2004

"Daniel Sj÷blom" <(E-Mail Removed)_NOSPAM> wrote in message
news:cm7u90$15u9$(E-Mail Removed)...
> Mark Bottomley wrote:
> >
> > iload (local variable containing a)
> > iload (local variable containing c)
> > iadd
> > i2b
> > istore (local variable containing b)
> >
> > this guarantees that the range of the addition result is trimmed to be
> > in the -128..127 range of a valid byte. The bytecodes that generated
> > the parameter for the the method call would compile to something
> > that guaranteed the value was in a range for the appropriate integer
> > subtype before it got to the method call

>
> But it is not enforced by the VM. There is no guarantee that a byte
> passed to a method really is in the byte range, which was the source of
> confusion, since it is (depending on how the text is to be interpreted)
> mentioned as a structural constraint in the spec. It is ok to pass any
> int value to a method taking a byte as argument (in the Sun VMs).
>
> Here is an example demonstrating what I mean (it will happily print any
> int value you pass to it):
>
> public class test.ByteTest extends java.lang.Object
> {
> public void <init>()
> {
> max stack: 1
> max locals: 1
>
> 0: aload_0
> 1: invokespecial java.lang.Object.<init>()
> 4: return
> }
>
> public static void main(java.lang.String[])
> {
> max stack: 2
> max locals: 1
>
> 0: aload_0
> 1: iconst_0
> 2: aaload
> 3: invokestatic java.lang.Integer.parseInt(java.lang.String)
> 6: invokestatic test.ByteTest.method(byte)
> 9: getstatic java.lang.System.out (java.io.PrintStream)
> 12: ldc "ok"
> 14: invokevirtual java.io.PrintStream.println(java.lang.String)
> 17: return
> }
>
> public static void method(byte)
> {
> max stack: 2
> max locals: 1
>
> 0: getstatic java.lang.System.out (java.io.PrintStream)
> 3: iload_0
> 4: invokevirtual java.io.PrintStream.println(int)
> 7: return
> }
> }
>
> --
> Daniel Sj÷blom
> Remove _NOSPAM to reply by mail


Daniel:

I agree - the difference is that althought a method can take any integer
or subtype as a parameter, the bytecodes provide ways for the compiler to
trim the integers to the requested range. The spec. only states that this is
not the VM's problem. The VM only manipulates 32/64 bit values. It can
logically trim or expand them for further internal use with x2y instructions
and it only really trims or extends them when reading/writing an array.

The VM was designed to support Java, however it also can and does
support other languages that compile to .class files.

Mark...


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MasterPage Method Invocation from ContentPage User ASP .Net 9 12-19-2005 11:20 AM
JNI question. UnsatisfiedLinkError upon method invocation CliffMacGillivray Java 7 09-15-2005 06:43 PM
inherited method invocation John N. Java 2 10-23-2003 07:28 PM
java.io.BufferedWriter and java.io.PrintStream - a seeming parameter/argument mismatch in method invocation Novice Java 1 07-19-2003 06:46 PM
Re: Help: Method invocation using an automation tool. D. Lane Java 0 06-27-2003 10:40 PM



Advertisments