< prev index next > src/java.base/share/classes/jdk/internal/classfile/impl/DirectClassBuilder.java
Print this page
/*
- * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
+ * 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
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 Util.Writable[] fields = EMPTY_WRITABLE_ARRAY;
+ 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;
return withMethod(builder);
}
// internal / for use by elements
- ClassBuilder withField(Util.Writable field) {
+ ClassBuilder withField(WritableField field) {
if (fieldsCount >= fields.length) {
int newCapacity = fieldsCount + 8;
this.fields = Arrays.copyOf(fields, newCapacity);
}
fields[fieldsCount++] = field;
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
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 >