public ClassFile(ModuleBinding moduleBinding, CompilerOptions options) { this.constantPool = new ConstantPool(this); this.targetJDK = options.targetJDK; this.produceAttributes = ClassFileConstants.ATTR_SOURCE; this.isNestedType = false; this.codeStream = new StackMapFrameCodeStream(this); initByteArrays(0); }
public int literalIndexForNameAndType(char[] name, char[] signature) { int index; if ((index = putInNameAndTypeCacheIfAbsent(name, signature, this.currentIndex)) < 0) { // The entry doesn't exit yet this.currentIndex++; if ((index = -index) > 0xFFFF){ this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType()); } int length = this.offsets.length; if (length <= index) { // resize System.arraycopy(this.offsets, 0, (this.offsets = new int[index * 2]), 0, length); } this.offsets[index] = this.currentOffset; writeU1(NameAndTypeTag); int nameIndexOffset = this.currentOffset; if (this.currentOffset + 4 >= this.poolContent.length) { resizePoolContents(4); } this.currentOffset+=4; final int nameIndex = literalIndex(name); final int typeIndex = literalIndex(signature); this.poolContent[nameIndexOffset++] = (byte) (nameIndex >> 8); this.poolContent[nameIndexOffset++] = (byte) nameIndex; this.poolContent[nameIndexOffset++] = (byte) (typeIndex >> 8); this.poolContent[nameIndexOffset] = (byte) typeIndex; } return index; } public int literalIndexForMethodHandle(MethodBinding binding) {
public int literalIndexForMethod(TypeBinding declaringClass, char[] selector, char[] signature, boolean isInterface) { if ((declaringClass.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { Util.recordNestedType(this.classFile, declaringClass); } return this.literalIndexForMethod(declaringClass.constantPoolName(), selector, signature, isInterface); } public int literalIndexForNameAndType(char[] name, char[] signature) {
public int literalIndexForInvokeDynamic(int bootStrapIndex, char[] selector, char[] descriptor) { int nameAndTypeIndex = literalIndexForNameAndType(selector, descriptor); int index = this.currentIndex++; int length = this.offsets.length; if (length <= index) { // resize System.arraycopy(this.offsets, 0, (this.offsets = new int[index * 2]), 0, length); } this.offsets[index] = this.currentOffset; writeU1(InvokeDynamicTag); writeU2(bootStrapIndex); writeU2(nameAndTypeIndex); return index; } public int literalIndexForField(char[] declaringClass, char[] name, char[] signature) {
public int literalIndexForField(char[] declaringClass, char[] name, char[] signature) { int index; if ((index = putInCacheIfAbsent(declaringClass, name, signature, this.currentIndex)) < 0) { this.currentIndex++; writeU1(FieldRefTag); int classIndexOffset = this.currentOffset; if (this.currentOffset + 4 >= this.poolContent.length) { resizePoolContents(4); final int classIndex = literalIndexForType(declaringClass); final int nameAndTypeIndex = literalIndexForNameAndType(name, signature);
int currentCodeStreamPosition = this.position; char[] constantChars = constant.toCharArray(); int index = this.constantPool.literalIndexForLdc(constantChars); if (index > 0) { System.arraycopy(constantChars, 0, subChars, 0, i); System.arraycopy(utf8encoding, 0, utf8encoding = new byte[length], 0, length); index = this.constantPool.literalIndex(subChars, utf8encoding); ldcForIndex(index); System.arraycopy(constantChars, startIndex, subChars, 0, newCharLength); System.arraycopy(utf8encoding, 0, utf8encoding = new byte[length], 0, length); index = this.constantPool.literalIndex(subChars, utf8encoding); ldcForIndex(index);
private int literalIndexForInvokeAndConstantDynamic(int bootStrapIndex, char[] selector, char[] descriptor, int tag) { int index; if ((index = putInDynamicCacheIfAbsent(bootStrapIndex, selector, descriptor, this.currentIndex)) < 0) { this.currentIndex++; if ((index = -index) > 0xFFFF){ this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType()); } int length = this.offsets.length; if (length <= index) { // resize System.arraycopy(this.offsets, 0, (this.offsets = new int[index * 2]), 0, length); } this.offsets[index] = this.currentOffset; writeU1(tag); int classIndexOffset = this.currentOffset; if (this.currentOffset + 4 >= this.poolContent.length) { resizePoolContents(4); } this.currentOffset+=4; int nameAndTypeIndex = literalIndexForNameAndType(selector, descriptor); this.poolContent[classIndexOffset++] = (byte) (bootStrapIndex >> 8); this.poolContent[classIndexOffset++] = (byte) bootStrapIndex; this.poolContent[classIndexOffset++] = (byte) (nameAndTypeIndex >> 8); this.poolContent[classIndexOffset] = (byte) nameAndTypeIndex; } return index; } // CONSTANT_Dynamic_info JVMS 4.4.10 /jep 309
this.constantPool.literalIndex(AttributeNamesConstants.EnclosingMethodName); this.contents[localContentsOffset++] = (byte) (enclosingMethodAttributeNameIndex >> 8); this.contents[localContentsOffset++] = (byte) enclosingMethodAttributeNameIndex; this.contents[localContentsOffset++] = 4; int enclosingTypeIndex = this.constantPool.literalIndexForType(this.referenceBinding.enclosingType().constantPoolName()); this.contents[localContentsOffset++] = (byte) (enclosingTypeIndex >> 8); this.contents[localContentsOffset++] = (byte) enclosingTypeIndex; MethodBinding methodBinding = ((LocalTypeBinding) this.referenceBinding).enclosingMethod; if (methodBinding != null) { int enclosingMethodIndex = this.constantPool.literalIndexForNameAndType(methodBinding.selector, methodBinding.signature(this)); methodIndexByte1 = (byte) (enclosingMethodIndex >> 8); methodIndexByte2 = (byte) enclosingMethodIndex;
public int literalIndex(TypeBinding binding) { TypeBinding typeBinding = binding.leafComponentType(); if ((typeBinding.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { Util.recordNestedType(this.classFile, typeBinding); } return literalIndex(binding.signature()); } /**
public void checkcast(TypeReference typeReference, TypeBinding typeBinding, int currentPosition) { this.countLabels = 0; if (this.classFileOffset + 2 >= this.bCodeStream.length) { resizeByteArray(); } this.position++; this.bCodeStream[this.classFileOffset++] = Opcodes.OPC_checkcast; writeUnsignedShort(this.constantPool.literalIndexForType(typeBinding)); }
/** * ConstantPool constructor comment. */ public ConstantPool(ClassFile classFile) { this.UTF8Cache = new CharArrayCache(UTF8_INITIAL_SIZE); this.stringCache = new CharArrayCache(STRING_INITIAL_SIZE); this.methodsAndFieldsCache = new HashtableOfObject(METHODS_AND_FIELDS_INITIAL_SIZE); this.classCache = new CharArrayCache(CLASS_INITIAL_SIZE); this.nameAndTypeCacheForFieldsAndMethods = new HashtableOfObject(NAMEANDTYPE_INITIAL_SIZE); this.offsets = new int[5]; initialize(classFile); } public void initialize(ClassFile givenClassFile) {
writeUnsignedShort(this.constantPool.literalIndexForField(declaringClass, fieldName, signature));
public int literalIndexForMethod(char[] declaringClass, char[] selector, char[] signature, boolean isInterface) { int index; if ((index = putInCacheIfAbsent(declaringClass, selector, signature, this.currentIndex)) < 0) { writeU1(isInterface ? InterfaceMethodRefTag : MethodRefTag); resizePoolContents(4); final int classIndex = literalIndexForType(declaringClass); final int nameAndTypeIndex = literalIndexForNameAndType(selector, signature);
public int literalIndexForInvokeDynamic(int bootStrapIndex, char[] selector, char[] descriptor) { int nameAndTypeIndex = literalIndexForNameAndType(selector, descriptor); int index = this.currentIndex++; int length = this.offsets.length; if (length <= index) { // resize System.arraycopy(this.offsets, 0, (this.offsets = new int[index * 2]), 0, length); } this.offsets[index] = this.currentOffset; writeU1(InvokeDynamicTag); writeU2(bootStrapIndex); writeU2(nameAndTypeIndex); return index; } public int literalIndexForField(char[] declaringClass, char[] name, char[] signature) {
int currentCodeStreamPosition = this.position; char[] constantChars = constant.toCharArray(); int index = this.constantPool.literalIndexForLdc(constantChars); if (index > 0) { System.arraycopy(constantChars, 0, subChars, 0, i); System.arraycopy(utf8encoding, 0, utf8encoding = new byte[length], 0, length); index = this.constantPool.literalIndex(subChars, utf8encoding); ldcForIndex(index); System.arraycopy(constantChars, startIndex, subChars, 0, newCharLength); System.arraycopy(utf8encoding, 0, utf8encoding = new byte[length], 0, length); index = this.constantPool.literalIndex(subChars, utf8encoding); ldcForIndex(index);
public int literalIndex(TypeBinding binding) { TypeBinding typeBinding = binding.leafComponentType(); if ((typeBinding.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { Util.recordNestedType(this.classFile, typeBinding); } return literalIndex(binding.signature()); } /**
public void checkcast(TypeReference typeReference, TypeBinding typeBinding, int currentPosition) { this.countLabels = 0; if (this.classFileOffset + 2 >= this.bCodeStream.length) { resizeByteArray(); } this.position++; this.bCodeStream[this.classFileOffset++] = Opcodes.OPC_checkcast; writeUnsignedShort(this.constantPool.literalIndexForType(typeBinding)); }
/** * ConstantPool constructor comment. */ public ConstantPool(ClassFile classFile) { this.UTF8Cache = new CharArrayCache(UTF8_INITIAL_SIZE); this.stringCache = new CharArrayCache(STRING_INITIAL_SIZE); this.methodsAndFieldsCache = new HashtableOfObject(METHODS_AND_FIELDS_INITIAL_SIZE); this.classCache = new CharArrayCache(CLASS_INITIAL_SIZE); this.nameAndTypeCacheForFieldsAndMethods = new HashtableOfObject(NAMEANDTYPE_INITIAL_SIZE); this.offsets = new int[5]; initialize(classFile); } public void initialize(ClassFile givenClassFile) {
writeUnsignedShort(this.constantPool.literalIndexForField(declaringClass, fieldName, signature));
public int literalIndexForMethod(char[] declaringClass, char[] selector, char[] signature, boolean isInterface) { int index; if ((index = putInCacheIfAbsent(declaringClass, selector, signature, this.currentIndex)) < 0) { writeU1(isInterface ? InterfaceMethodRefTag : MethodRefTag); resizePoolContents(4); final int classIndex = literalIndexForType(declaringClass); final int nameAndTypeIndex = literalIndexForNameAndType(selector, signature);