From leonid.kuskov at oracle.com Thu Mar 12 23:43:10 2015 From: leonid.kuskov at oracle.com (Leonid Kuskov) Date: Thu, 12 Mar 2015 16:43:10 -0700 Subject: the main method in an interface Message-ID: <5502248E.8040101@oracle.com> Hello Alex, JVMS and JLS don't take into account that the main method can be in an interface. Assertion jvms-5.5-110-F states "If C is a class, its designation as the initial class at Java Virtual Machine startup". But C may be an interface also. HotSpot initializes such interface successfully. $ cat Intf.jasm public interface Intf version 52:0 { public static Method main:"([Ljava/lang/String;)V" stack 2 locals 1 { getstatic Field java/lang/System.out:"Ljava/io/PrintStream;"; ldc String "Hello, world!"; invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V"; return; } static Method "":"()V" stack 2 locals 0 { getstatic Field java/lang/System.out:"Ljava/io/PrintStream;"; ldc String "initialized"; invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V"; return; } } // end Class Intf Output: $ java Intf initialized Hello, world! Looks like JLS and JVMS don't take into account interfaces with the main method in other places too (JVMS 5.2, JLS 12.1, maybe more). And second question is: Umbrella assertion jvms-5.5-110 includes assertions about the ways how a class can be initialized (execution of new/getstatic/putstatic/invokestatic, invocation of MethodHandle etc). Each of them, except invocation of reflective methods, clarifies that a class will be initialized only if it hasn't been initialized already. Why there is no such clarification for reflection (jvms-5.5-110-C)? Thanks, Leonid From alex.buckley at oracle.com Fri Mar 13 21:12:40 2015 From: alex.buckley at oracle.com (Alex Buckley) Date: Fri, 13 Mar 2015 14:12:40 -0700 Subject: the main method in an interface In-Reply-To: <5502248E.8040101@oracle.com> References: <5502248E.8040101@oracle.com> Message-ID: <550352C8.2080405@oracle.com> Hi Leonid, On 3/12/2015 4:43 PM, Leonid Kuskov wrote: > Hello Alex, > > JVMS and JLS don't take into account that the main method can be in an > interface. > Assertion jvms-5.5-110-F states "If C is a class, its designation as the > initial class at Java Virtual Machine startup". > But C may be an interface also. HotSpot initializes such interface > successfully. > $ cat Intf.jasm > public interface Intf > version 52:0 > { > > public static Method main:"([Ljava/lang/String;)V" > stack 2 locals 1 > { > getstatic Field > java/lang/System.out:"Ljava/io/PrintStream;"; > ldc String "Hello, world!"; > invokevirtual Method > java/io/PrintStream.println:"(Ljava/lang/String;)V"; > return; > > } > > static Method "":"()V" > stack 2 locals 0 > { > getstatic Field > java/lang/System.out:"Ljava/io/PrintStream;"; > ldc String "initialized"; > invokevirtual Method > java/io/PrintStream.println:"(Ljava/lang/String;)V"; > return; > } > > } // end Class Intf > > Output: > $ java Intf > initialized > Hello, world! > > Looks like JLS and JVMS don't take into account interfaces with the main > method in other places too (JVMS 5.2, JLS 12.1, maybe more). Thanks for spotting that we really support an initial class _or interface_. I confirmed with Brian Goetz that this is intentional, and have filed https://bugs.openjdk.java.net/browse/JDK-8075167. > And second question is: > > Umbrella assertion jvms-5.5-110 includes assertions about the ways how a > class can be initialized (execution of > new/getstatic/putstatic/invokestatic, invocation of MethodHandle etc). > Each of them, except invocation of reflective methods, clarifies that a > class will be initialized only if it hasn't been initialized already. > Why there is no such clarification for reflection (jvms-5.5-110-C)? There are six clauses under the umbrella "only as a result of" assertion; only the first says "if it has not been initialized already." That's both redundant (since the initialization algorithm itself doesn't reinitialize) and potentially confusing (because it can be read as implying that initialization always succeeds). I have filed https://bugs.openjdk.java.net/browse/JDK-8075168. I think the question about why the reflective clause doesn't say it is now moot (and in any case the JVMS tries to make very few commitments about the behavior of reflection). Alex From thank-the-lord at gmx.de Sat Mar 14 17:31:01 2015 From: thank-the-lord at gmx.de (thank-the-lord at gmx.de) Date: Sat, 14 Mar 2015 18:31:01 +0100 Subject: JVMS8 RuntimeVisibleTypeAnnotations Attribute Message-ID: An embedded and charset-unspecified text was scrubbed... Name: JSE8TypeAnnotationExample.java URL: From johnny.gerard at hotmail.com Sun Mar 29 20:30:21 2015 From: johnny.gerard at hotmail.com (=?UTF-8?B?Sm9obm55IEfDqXJhcmQ=?=) Date: Sun, 29 Mar 2015 22:30:21 +0200 Subject: switch statement definition Message-ID: Hi, I find the switch statement syntactic definition pretty unclear. I'd like to know if the following definition is correct and could be a new definition for the specification : *SwitchStatement*: switch ( Expression ) SwitchBlock *SwitchBlock*: { /{/SwitchLabel/}/ } { SwitchLabels BlockStatements /{/SwitchBlockStatement/}/ } *SwitchBlockStatement*: SwitchLabel BlockStatement So, to be clear : I replaced *SwitchBlock* by a new one and**created the non terminal symbol *SwitchBlockStatement*. This new *SwitchStatement *is not using the *SwitchBlockStatementGroup* symbol. I hope this is clear enough. Johnny G?rard --- L'absence de virus dans ce courrier ?lectronique a ?t? v?rifi?e par le logiciel antivirus Avast. http://www.avast.com