Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8178959

Java AOT compiler runs clinit during compilation

XMLWordPrintable

    • x86_64
    • linux

      A DESCRIPTION OF THE REQUEST :
      I found that the aot compiler runs clinit during the compilation. In case that the clinit contains some dangerous code, it may cause troubles. The following class successfully writes a file when it is compiled using jaotc.

      public class Vector1 extends java.util.AbstractList
        minor version: 0
        major version: 52
        flags: ACC_PUBLIC, ACC_SUPER
      Constant pool:
         #1 = Utf8 Vector1
         #2 = Class #1 // Vector1
         #3 = Utf8 java/util/AbstractList
         #4 = Class #3 // java/util/AbstractList
         #5 = Utf8 elementData
         #6 = Utf8 [Ljava/lang/Object;
         #7 = Utf8 elementCount
         #8 = Utf8 I
         #9 = Utf8 capacityIncrement
        #10 = Utf8 serialVersionUID
        #11 = Utf8 J
        #12 = Long -2767605614048989439l
        #14 = Utf8 MAX_ARRAY_SIZE
        #15 = Integer 2147483639
        #16 = Utf8 <clinit>
        #17 = Utf8 ()V
        #18 = Utf8 @68--public static void <clinit>()
        #19 = String #18 // @68--public static void <clinit>()
        #20 = Utf8 _DTJVM_Print
        #21 = Class #20 // _DTJVM_Print
        #22 = Utf8 print
        #23 = Utf8 (Ljava/lang/String;)V
        #24 = NameAndType #22:#23 // print:(Ljava/lang/String;)V
        #25 = Methodref #21.#24 // _DTJVM_Print.print:(Ljava/lang/String;)V
        #26 = Utf8 @68$0
        #27 = String #26 // @68$0
        #28 = NameAndType #14:#8 // MAX_ARRAY_SIZE:I
        #29 = Fieldref #2.#28 // Vector1.MAX_ARRAY_SIZE:I
        #30 = Utf8 @68$9897683
        #31 = String #30 // @68$9897683
        #32 = Utf8 @68$1
        #33 = String #32 // @68$1
        #34 = NameAndType #10:#11 // serialVersionUID:J
        #35 = Fieldref #2.#34 // Vector1.serialVersionUID:J
        #36 = Utf8 @68$2
        #37 = String #36 // @68$2
        #38 = Utf8 ConstantValue
        #39 = Utf8 Code
        #40 = Utf8 StackMapTable
      {
        protected java.lang.Object[] elementData;
          descriptor: [Ljava/lang/Object;
          flags: ACC_PROTECTED

        protected int elementCount;
          descriptor: I
          flags: ACC_PROTECTED

        protected int capacityIncrement;
          descriptor: I
          flags: ACC_PROTECTED

        public static {};
          descriptor: ()V
          flags: ACC_PUBLIC, ACC_STATIC
          Code:
            stack=2, locals=1, args_size=0
               0: ldc #19 // String @68--public static void <clinit>()
               2: invokestatic #25 // Method _DTJVM_Print.print:(Ljava/lang/String;)V
               5: bipush 35
               7: istore_0
               8: ldc #27 // String @68$0
              10: invokestatic #25 // Method _DTJVM_Print.print:(Ljava/lang/String;)V
              13: ldc #15 // int 2147483639
              15: putstatic #29 // Field MAX_ARRAY_SIZE:I
              18: ldc #31 // String @68$9897683
              20: invokestatic #25 // Method _DTJVM_Print.print:(Ljava/lang/String;)V
              23: iinc 0, -1
              26: iload_0
              27: ifge 8
              30: ldc #33 // String @68$1
              32: invokestatic #25 // Method _DTJVM_Print.print:(Ljava/lang/String;)V
              35: ldc2_w #12 // long -2767605614048989439l
              38: putstatic #35 // Field serialVersionUID:J
              41: ldc #37 // String @68$2
              43: invokestatic #25 // Method _DTJVM_Print.print:(Ljava/lang/String;)V
              46: return
            StackMapTable: number_of_entries = 1
              frame_type = 252 /* append */
                offset_delta = 8
                locals = [ int ]
      }




      JUSTIFICATION :
      We should not use jaotc to compile bytecode if we do not fully understand/trust the code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Do not have any external behaviors during compilation.
      ACTUAL -
      Writes an external file.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: