RFR:JDK-8190391:nashorn: "!!" of nonzero even integer var becomes false when returned
Sundararajan Athijegannathan
sundararajan.athijegannathan at oracle.com
Mon Nov 13 08:27:51 UTC 2017
Experimented with jasm
(https://wiki.openjdk.java.net/display/CodeTools/asmtools):
super public class HelloWorld
version 50:0
{
public Method "<init>":"()V"
stack 1 locals 1
{
aload_0;
invokespecial Method java/lang/Object."<init>":"()V";
return;
}
public static Method func:"(I)Z"
stack 1 locals 1
{
iload 0;
ireturn;
}
public static Method main:"([Ljava/lang/String;)V"
stack 2 locals 1
{
getstatic Field
java/lang/System.out:"Ljava/io/PrintStream;";
bipush 0;
invokestatic Method HelloWorld.func:"(I)Z";
invokevirtual Method java/io/PrintStream.println:"(Z)V";
getstatic Field
java/lang/System.out:"Ljava/io/PrintStream;";
bipush 13;
invokestatic Method HelloWorld.func:"(I)Z";
invokevirtual Method java/io/PrintStream.println:"(Z)V";
getstatic Field
java/lang/System.out:"Ljava/io/PrintStream;";
bipush 22;
invokestatic Method HelloWorld.func:"(I)Z";
invokevirtual Method java/io/PrintStream.println:"(Z)V";
return;
}
} // end Class HelloWorld
prints false, true, false.
-Sundar
On 13/11/17, 1:42 PM, Sundararajan Athijegannathan wrote:
> +1
>
> Yep. 0 and 1 are only allowed.
>
> -Sundar
>
> On 13/11/17, 1:27 PM, Attila Szegedi wrote:
>> +1. Nice catch. Feels like an implementation detail, but the JVM
>> specification is indeed unclear on the behavior in case there's a
>> bytecode
>> method doing this:
>>
>> public static func(I)Z
>> 0 iload 0
>> 1 ireturn
>>
>>
>> I went spelunking in the JVM spec, and the closest I could find is in
>> section 2.3.4 says "The Java Virtual Machine encodes boolean array
>> components using 1 to represent true and 0 to represent false. Where
>> Java
>> programming language boolean values are mapped by compilers to values of
>> Java Virtual Machine type int, the compilers must use the same
>> encoding."
>> So I guess we better stick to that.
>>
>> Attila.
>>
>>
>> On Mon, Nov 13, 2017 at 7:21 AM, Priya Lakshmi Muthuswamy<
>> priya.lakshmi.muthuswamy at oracle.com> wrote:
>>
>>> Hi,
>>>
>>> Please review JDK-8190391 : nashorn: "!!" of nonzero even integer var
>>> becomes false when returned
>>>
>>> JBS : https://bugs.openjdk.java.net/browse/JDK-8190391
>>> webrev : http://cr.openjdk.java.net/~pmuthuswamy/8190391/webrev.00/
>>>
>>> Thanks,
>>> Priya
>>>
More information about the nashorn-dev
mailing list