< prev index next >

src/java.base/share/classes/jdk/internal/classfile/impl/DirectClassBuilder.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
   * Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
--- 1,7 ---
  /*
!  * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
   * Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as

*** 42,13 ***
          implements ClassBuilder {
  
      /** The value of default class access flags */
      static final int DEFAULT_CLASS_FLAGS = ClassFile.ACC_PUBLIC;
      static final Util.Writable[] EMPTY_WRITABLE_ARRAY = {};
      static final ClassEntry[] EMPTY_CLASS_ENTRY_ARRAY = {};
      final ClassEntry thisClassEntry;
!     private Util.Writable[] fields = EMPTY_WRITABLE_ARRAY;
      private Util.Writable[] methods = EMPTY_WRITABLE_ARRAY;
      private int fieldsCount = 0;
      private int methodsCount = 0;
      private ClassEntry superclassEntry;
      private List<ClassEntry> interfaceEntries;
--- 42,14 ---
          implements ClassBuilder {
  
      /** The value of default class access flags */
      static final int DEFAULT_CLASS_FLAGS = ClassFile.ACC_PUBLIC;
      static final Util.Writable[] EMPTY_WRITABLE_ARRAY = {};
+     static final WritableField[] EMPTY_WRITABLE_FIELD_ARRAY = {};
      static final ClassEntry[] EMPTY_CLASS_ENTRY_ARRAY = {};
      final ClassEntry thisClassEntry;
!     private WritableField[] fields = EMPTY_WRITABLE_FIELD_ARRAY;
      private Util.Writable[] methods = EMPTY_WRITABLE_ARRAY;
      private int fieldsCount = 0;
      private int methodsCount = 0;
      private ClassEntry superclassEntry;
      private List<ClassEntry> interfaceEntries;

*** 127,11 ***
          return withMethod(builder);
      }
  
      // internal / for use by elements
  
!     ClassBuilder withField(Util.Writable field) {
          if (fieldsCount >= fields.length) {
              int newCapacity = fieldsCount + 8;
              this.fields = Arrays.copyOf(fields, newCapacity);
          }
          fields[fieldsCount++] = field;
--- 128,11 ---
          return withMethod(builder);
      }
  
      // internal / for use by elements
  
!     ClassBuilder withField(WritableField field) {
          if (fieldsCount >= fields.length) {
              int newCapacity = fieldsCount + 8;
              this.fields = Arrays.copyOf(fields, newCapacity);
          }
          fields[fieldsCount++] = field;

*** 166,11 ***
  
      public void setSizeHint(int sizeHint) {
          this.sizeHint = sizeHint;
      }
  
- 
      public byte[] build() {
  
          // The logic of this is very carefully ordered.  We want to avoid
          // repeated buffer copyings, so we accumulate lists of writers which
          // all get written later into the same buffer.  But, writing can often
--- 167,10 ---

*** 193,10 ***
--- 193,12 ---
          BufWriterImpl tail = new BufWriterImpl(constantPool, context, size, thisClassEntry, majorVersion);
  
          // The tail consists of fields and methods, and attributes
          // This should trigger all the CP/BSM mutation
          Util.writeList(tail, fields, fieldsCount);
+         var strictInstanceFields = WritableField.filterStrictInstanceFields(constantPool, fields, fieldsCount);
+         tail.setStrictInstanceFields(strictInstanceFields);
          Util.writeList(tail, methods, methodsCount);
          int attributesOffset = tail.size();
          attributes.writeTo(tail);
  
          // Now we have to append the BSM, if there is one
< prev index next >