From anthony.vanelverdinghe at gmail.com Sun Jul 12 12:10:50 2015 From: anthony.vanelverdinghe at gmail.com (Anthony Vanelverdinghe) Date: Sun, 12 Jul 2015 14:10:50 +0200 Subject: Example 6.6-5: unhelpful reference to section 8.8.8 Message-ID: <55A2594A.1080906@gmail.com> Dear Java SE Specification Leads Example 6.6-5 [1] mentions at the bottom "See ?8.8.8 for an example that uses a private constructor." However, section 8.8.8 contains no such example. I believe the intended reference is to section 8.8.10 instead, more specifically Example 8.8.10-1 [1] http://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.6.1 Kind regards, Anthony Vanelverdinghe From chenyt at cs.sjtu.edu.cn Thu Jul 9 00:21:32 2015 From: chenyt at cs.sjtu.edu.cn (Yuting Chen) Date: Wed, 8 Jul 2015 17:21:32 -0700 Subject: An undefined behavior w.r.t. Message-ID: Hello, I recently feel puzzling about the JVM behaviors when an illegal is met. The specification may not be complete in this part. In the specification (jvms-2.9, se8), we have the words: "In a class file whose version number is 51.0 or above, the method must additionally have its ACC_STATIC flag (?4.6) set in order to be the class or interface initialization method." However, the behavior is undefined if the ACC_STATIC flag is not set. Thus when a class without an ACC_STATIC flag may either be accepted or be rejected, depending on the JVM developers. The results can be unpredictable. I checked this by running a class on OpenJDK8-HotSpot and IBM J9, and found different results. The class can be run on HotSpot without triggering any exceptions (i.e., is of no consequence). However, IBM J9 can throw out a FormatError (Exception in thread "main" java.lang.ClassFormatError: JVMCFRE074 no Code attribute specified; class=M1436188543, method=()V, pc=0). I checked the specification and still could not decide which JVM behaves correctly. The class is attached, and the decompiled code is given next: class M1436188543 minor version: 0 major version: 51 flags: ACC_SUPER Constant pool: #1 = Utf8 java/lang/Object #2 = Utf8 #3 = Utf8 SourceFile #4 = Utf8 M1436188543 #5 = Utf8 main #6 = Class #4 // M1436188543 #7 = Utf8 Code #8 = Utf8 ([Ljava/lang/String;)V #9 = Utf8 ()V #10 = Utf8 Jasmin #11 = Class #1 // java/lang/Object { public abstract {}; descriptor: ()V flags: ACC_PUBLIC, ACC_ABSTRACT public static void main(java.lang.String[]); descriptor: ([Ljava/lang/String;)V flags: ACC_PUBLIC, ACC_STATIC Code: stack=0, locals=1, args_size=1 0: return } From chenyt at cs.sjtu.edu.cn Sun Jul 12 19:41:12 2015 From: chenyt at cs.sjtu.edu.cn (Yuting Chen) Date: Sun, 12 Jul 2015 12:41:12 -0700 Subject: An undefined behavior w.r.t. In-Reply-To: References: Message-ID: Should the text in jvms 2.9 be changed? The statement "Other methods named in a class file are of no consequence" is not very clear. I guess the correct representation should be "Methods named are of no consequence if they are not class or interface initialization methods." Suggestions: " The initialization method of a class or interface has the special name , takes no arguments, and is void (?4.3.3). Other methods named in a class file are of no consequence. They are not class or interface initialization methods. They cannot be invoked by any Java Virtual Machine instruction and are never invoked by the Java Virtual Machine itself. " => " The initialization method of a class or interface has the special name , takes no arguments, and is void (?4.3.3). Other methods named are not class or interface initialization methods. They cannot be invoked by any Java Virtual Machine instruction and are never invoked by the Java Virtual Machine itself. Methods named are of no consequence if they are not class or interface initialization methods. " On Wed, Jul 8, 2015 at 5:21 PM, Yuting Chen wrote: > Hello, I recently feel puzzling about the JVM behaviors when an illegal > is met. The specification may not be complete in this part. > > In the specification (jvms-2.9, se8), we have the words: "In a class file > whose version number is 51.0 or above, the method must additionally have its > ACC_STATIC flag (?4.6) set in order to be the class or interface > initialization method." > > However, the behavior is undefined if the ACC_STATIC flag is not set. Thus > when a class without an ACC_STATIC flag may either be accepted or be > rejected, depending on the JVM developers. The results can be unpredictable. > > I checked this by running a class on OpenJDK8-HotSpot and IBM J9, and found > different results. The class can be run on HotSpot without triggering any > exceptions (i.e., is of no consequence). However, IBM J9 can throw > out a FormatError (Exception in thread "main" java.lang.ClassFormatError: > JVMCFRE074 no Code attribute specified; class=M1436188543, > method=()V, pc=0). I checked the specification and still could not > decide which JVM behaves correctly. > > The class is attached, and the decompiled code is given next: > > class M1436188543 > minor version: 0 > major version: 51 > flags: ACC_SUPER > Constant pool: > #1 = Utf8 java/lang/Object > #2 = Utf8 > #3 = Utf8 SourceFile > #4 = Utf8 M1436188543 > #5 = Utf8 main > #6 = Class #4 // M1436188543 > #7 = Utf8 Code > #8 = Utf8 ([Ljava/lang/String;)V > #9 = Utf8 ()V > #10 = Utf8 Jasmin > #11 = Class #1 // java/lang/Object > { > public abstract {}; > descriptor: ()V > flags: ACC_PUBLIC, ACC_ABSTRACT > > public static void main(java.lang.String[]); > descriptor: ([Ljava/lang/String;)V > flags: ACC_PUBLIC, ACC_STATIC > Code: > stack=0, locals=1, args_size=1 > 0: return > } > From alex.buckley at oracle.com Mon Jul 20 21:08:25 2015 From: alex.buckley at oracle.com (Alex Buckley) Date: Mon, 20 Jul 2015 14:08:25 -0700 Subject: Example 6.6-5: unhelpful reference to section 8.8.8 In-Reply-To: <55A2594A.1080906@gmail.com> References: <55A2594A.1080906@gmail.com> Message-ID: <55AD6349.2080406@oracle.com> Anthony, thanks for the correction. Alex On 7/12/2015 5:10 AM, Anthony Vanelverdinghe wrote: > Dear Java SE Specification Leads > > Example 6.6-5 [1] mentions at the bottom "See ?8.8.8 for an example that > uses a private constructor." > However, section 8.8.8 contains no such example. I believe the intended > reference is to section 8.8.10 instead, more specifically Example 8.8.10-1 > > [1] http://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.6.1 > > Kind regards, > Anthony Vanelverdinghe > From alex.buckley at oracle.com Mon Jul 20 21:26:46 2015 From: alex.buckley at oracle.com (Alex Buckley) Date: Mon, 20 Jul 2015 14:26:46 -0700 Subject: An undefined behavior w.r.t. In-Reply-To: References: Message-ID: <55AD6796.2050206@oracle.com> Yuting, In a 51.0 class file, a method called whose ACC_STATIC flag is not set is NOT a class or interface initialization method. It's just an ordinary method that happens to be uncallable. There's nothing "undefined" about that. Since it's an ordinary method, it can be ACC_ABSTRACT and have no Code attribute, so J9 is wrong to throw a CFE for it. It just so happens that Oracle engineers were investigating methods called earlier this month. I filed a spec clarification: https://bugs.openjdk.java.net/browse/JDK-8130682 Alex On 7/8/2015 5:21 PM, Yuting Chen wrote: > Hello, I recently feel puzzling about the JVM behaviors when an illegal > is met. The specification may not be complete in this part. > > In the specification (jvms-2.9, se8), we have the words: "In a class file > whose version number is 51.0 or above, the method must additionally have > its ACC_STATIC flag (?4.6) set in order to be the class or interface > initialization method." > > However, the behavior is undefined if the ACC_STATIC flag is not set. Thus > when a class without an ACC_STATIC flag may either be accepted or be > rejected, depending on the JVM developers. The results can be unpredictable. > > I checked this by running a class on OpenJDK8-HotSpot and IBM J9, and found > different results. The class can be run on HotSpot without triggering any > exceptions (i.e., is of no consequence). However, IBM J9 can throw > out a FormatError (Exception in thread "main" java.lang.ClassFormatError: > JVMCFRE074 no Code attribute specified; class=M1436188543, > method=()V, pc=0). I checked the specification and still could not > decide which JVM behaves correctly. > > The class is attached, and the decompiled code is given next: > > class M1436188543 > minor version: 0 > major version: 51 > flags: ACC_SUPER > Constant pool: > #1 = Utf8 java/lang/Object > #2 = Utf8 > #3 = Utf8 SourceFile > #4 = Utf8 M1436188543 > #5 = Utf8 main > #6 = Class #4 // M1436188543 > #7 = Utf8 Code > #8 = Utf8 ([Ljava/lang/String;)V > #9 = Utf8 ()V > #10 = Utf8 Jasmin > #11 = Class #1 // java/lang/Object > { > public abstract {}; > descriptor: ()V > flags: ACC_PUBLIC, ACC_ABSTRACT > > public static void main(java.lang.String[]); > descriptor: ([Ljava/lang/String;)V > flags: ACC_PUBLIC, ACC_STATIC > Code: > stack=0, locals=1, args_size=1 > 0: return > } >