From 6898274f4782ba93fdd9d1a121cac9bf3d7dcfa5 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 27 Sep 2013 17:42:28 +0400 Subject: [PATCH] Delete JvmClassName.getDescriptor() It shouldn't be available in descriptor.loader.java, since it wouldn't depend on ASM and its descriptors won't make any sense there. Most of the places where this method was used were in codegen. The few exceptions are reading annotations for compiled Kotlin classes by ASM visitors, but that will be abstracted away soon --- .../org/jetbrains/jet/codegen/AsmUtil.java | 2 +- .../jetbrains/jet/codegen/CallableMethod.java | 17 +++--------- .../jetbrains/jet/codegen/ClosureCodegen.java | 23 ++++++++-------- .../jet/codegen/FunctionCodegen.java | 12 ++++----- .../jet/codegen/NamespaceCodegen.java | 2 +- .../jetbrains/jet/codegen/ScriptCodegen.java | 5 ++-- .../jet/codegen/intrinsics/ArrayIterator.java | 26 ++++++++++--------- .../jet/lang/resolve/java/JvmClassName.java | 11 +------- 8 files changed, 38 insertions(+), 60 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java index 1fdc00c81a8..715366d4a99 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java @@ -667,6 +667,6 @@ public class AsmUtil { @NotNull public static String asmDescByFqNameWithoutInnerClasses(@NotNull FqName fqName) { - return JvmClassName.byFqNameWithoutInnerClasses(fqName).getDescriptor(); + return "L" + JvmClassName.byFqNameWithoutInnerClasses(fqName).getInternalName() + ';'; } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java b/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java index ca47be38717..6741972d4b3 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java @@ -38,7 +38,7 @@ public class CallableMethod implements Callable { @Nullable private final JvmClassName defaultImplOwner; @Nullable - private final JvmClassName defaultImplParam; + private final Type defaultImplParam; private final JvmMethodSignature signature; private final int invokeOpcode; @Nullable @@ -55,7 +55,7 @@ public class CallableMethod implements Callable { ) { this.owner = owner; this.defaultImplOwner = defaultImplOwner; - this.defaultImplParam = defaultImplParam; + this.defaultImplParam = defaultImplParam == null ? null : defaultImplParam.getAsmType(); this.signature = signature; this.invokeOpcode = invokeOpcode; this.thisClass = thisClass; @@ -68,11 +68,6 @@ public class CallableMethod implements Callable { return owner; } - @Nullable - public JvmClassName getDefaultImplParam() { - return defaultImplParam; - } - public JvmMethodSignature getSignature() { return signature; } @@ -157,12 +152,6 @@ public class CallableMethod implements Callable { @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(Printer.OPCODES[invokeOpcode]); - sb.append(" "); - sb.append(owner); - sb.append("."); - sb.append(signature); - return sb.toString(); + return Printer.OPCODES[invokeOpcode] + " " + owner + "." + signature; } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java index 65883123358..416d3c921a1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java @@ -60,7 +60,7 @@ public class ClosureCodegen extends GenerationStateAware { private final CodegenContext context; private final FunctionGenerationStrategy strategy; private final CalculatedClosure closure; - private final JvmClassName name; + private final Type asmType; private Method constructor; @@ -87,12 +87,12 @@ public class ClosureCodegen extends GenerationStateAware { this.closure = bindingContext.get(CLOSURE, classDescriptor); assert closure != null : "Closure must be calculated for class: " + classDescriptor; - this.name = classNameForAnonymousClass(bindingContext, funDescriptor); + this.asmType = classNameForAnonymousClass(bindingContext, funDescriptor).getAsmType(); } public void gen() { - ClassBuilder cv = state.getFactory().newVisitor(name, fun.getContainingFile()); + ClassBuilder cv = state.getFactory().newVisitor(JvmClassName.byType(asmType), fun.getContainingFile()); FunctionDescriptor interfaceFunction; String[] superInterfaces; @@ -109,7 +109,7 @@ public class ClosureCodegen extends GenerationStateAware { cv.defineClass(fun, V1_6, ACC_FINAL | ACC_SUPER, - name.getInternalName(), + asmType.getInternalName(), getGenericSignature(), superClass.getInternalName(), superInterfaces @@ -141,16 +141,15 @@ public class ClosureCodegen extends GenerationStateAware { @NotNull public StackValue putInstanceOnStack(@NotNull InstructionAdapter v, @NotNull ExpressionCodegen codegen) { - Type asmType = name.getAsmType(); if (isConst(closure)) { - v.getstatic(name.getInternalName(), JvmAbi.INSTANCE_FIELD, name.getDescriptor()); + v.getstatic(asmType.getInternalName(), JvmAbi.INSTANCE_FIELD, asmType.getDescriptor()); } else { v.anew(asmType); v.dup(); codegen.pushClosureOnStack(closure, false); - v.invokespecial(name.getInternalName(), "", constructor.getDescriptor()); + v.invokespecial(asmType.getInternalName(), "", constructor.getDescriptor()); } return StackValue.onStack(asmType); } @@ -160,14 +159,14 @@ public class ClosureCodegen extends GenerationStateAware { MethodVisitor mv = cv.newMethod(fun, ACC_STATIC | ACC_SYNTHETIC, "", "()V", null, ArrayUtil.EMPTY_STRING_ARRAY); InstructionAdapter iv = new InstructionAdapter(mv); - cv.newField(fun, ACC_STATIC | ACC_FINAL, JvmAbi.INSTANCE_FIELD, name.getDescriptor(), null, null); + cv.newField(fun, ACC_STATIC | ACC_FINAL, JvmAbi.INSTANCE_FIELD, asmType.getDescriptor(), null, null); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { genStubCode(mv); } else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { mv.visitCode(); - genInitSingletonField(name.getAsmType(), iv); + genInitSingletonField(asmType, iv); mv.visitInsn(RETURN); FunctionCodegen.endVisit(mv, "", fun); } @@ -192,7 +191,7 @@ public class ClosureCodegen extends GenerationStateAware { InstructionAdapter iv = new InstructionAdapter(mv); - iv.load(0, name.getAsmType()); + iv.load(0, asmType); ReceiverParameterDescriptor receiver = funDescriptor.getReceiverParameter(); int count = 1; @@ -207,7 +206,7 @@ public class ClosureCodegen extends GenerationStateAware { count++; } - iv.invokevirtual(name.getInternalName(), interfaceFunction.getName().asString(), delegate.getDescriptor()); + iv.invokevirtual(asmType.getInternalName(), interfaceFunction.getName().asString(), delegate.getDescriptor()); StackValue.onStack(delegate.getReturnType()).put(bridge.getReturnType(), iv); iv.areturn(bridge.getReturnType()); @@ -218,7 +217,7 @@ public class ClosureCodegen extends GenerationStateAware { @NotNull private Method generateConstructor(@NotNull ClassBuilder cv) { - List args = calculateConstructorParameters(typeMapper, closure, name.getAsmType()); + List args = calculateConstructorParameters(typeMapper, closure, asmType); Type[] argTypes = fieldListToTypeArray(args); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 3d2b2ad5850..e22a6e8544c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -532,17 +532,15 @@ public class FunctionCodegen extends GenerationStateAware { int flags = ACC_PUBLIC | ACC_SYNTHETIC; // TODO. - JvmClassName ownerInternalName; + Type ownerType; if (contextClass instanceof NamespaceDescriptor) { - ownerInternalName = state.getTypeMapper().getOwner(functionDescriptor, kind, true); + ownerType = state.getTypeMapper().getOwner(functionDescriptor, kind, true).getAsmType(); } else if (contextClass instanceof ClassDescriptor) { - ownerInternalName = JvmClassName.byType(state.getTypeMapper() - .mapType(((ClassDescriptor) contextClass).getDefaultType(), - JetTypeMapperMode.IMPL)); + ownerType = state.getTypeMapper().mapType(((ClassDescriptor) contextClass).getDefaultType(), JetTypeMapperMode.IMPL); } else if (isLocalNamedFun(functionDescriptor)) { - ownerInternalName = classNameForAnonymousClass(state.getBindingContext(), functionDescriptor); + ownerType = classNameForAnonymousClass(state.getBindingContext(), functionDescriptor).getAsmType(); } else { throw new IllegalStateException("Couldn't obtain owner name for " + functionDescriptor); @@ -551,7 +549,7 @@ public class FunctionCodegen extends GenerationStateAware { String descriptor = jvmSignature.getDescriptor().replace(")", "I)"); boolean isConstructor = "".equals(jvmSignature.getName()); if (!isStatic && !isConstructor) { - descriptor = descriptor.replace("(", "(" + ownerInternalName.getDescriptor()); + descriptor = descriptor.replace("(", "(" + ownerType.getDescriptor()); } MethodVisitor mv = v.newMethod(null, flags | (isConstructor ? 0 : ACC_STATIC), isConstructor ? "" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java index 52c113b61a8..d29158d1c2d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java @@ -217,7 +217,7 @@ public class NamespaceCodegen extends MemberCodegen { } private static void writeKotlinPackageFragmentAnnotation(@NotNull ClassBuilder builder) { - AnnotationVisitor av = builder.newAnnotation(JvmClassName.byFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_PACKAGE_FRAGMENT).getDescriptor(), true); + AnnotationVisitor av = builder.newAnnotation(asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_PACKAGE_FRAGMENT), true); av.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION); av.visitEnd(); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java index 391d4a6e9c0..c34b783fc13 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java @@ -182,10 +182,9 @@ public class ScriptCodegen extends MemberCodegen { private void genFieldsForParameters(@NotNull ScriptDescriptor script, @NotNull ClassBuilder classBuilder) { for (ScriptDescriptor earlierScript : earlierScripts) { - JvmClassName earlierClassName; - earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript); + JvmClassName earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript); int access = ACC_PRIVATE | ACC_FINAL; - classBuilder.newField(null, access, getScriptFieldName(earlierScript), earlierClassName.getDescriptor(), null, null); + classBuilder.newField(null, access, getScriptFieldName(earlierScript), earlierClassName.getAsmType().getDescriptor(), null, null); } for (ValueParameterDescriptor parameter : script.getValueParameters()) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java index 7d4ba805a82..2cab1b1c7fb 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java @@ -30,13 +30,15 @@ import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; -import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType; +import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.PrimitiveType; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses; + public class ArrayIterator implements IntrinsicMethod { @Override public StackValue generate( @@ -58,18 +60,18 @@ public class ArrayIterator implements IntrinsicMethod { v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;)Ljava/util/Iterator;"); return StackValue.onStack(AsmTypeConstants.JET_ITERATOR_TYPE); } - else { - for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { - PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); - ClassDescriptor arrayClass = KotlinBuiltIns.getInstance().getPrimitiveArrayClassDescriptor(primitiveType); - if (containingDeclaration.equals(arrayClass)) { - JvmClassName iterator = JvmClassName.byFqNameWithoutInnerClasses("jet." + primitiveType.getTypeName() + "Iterator"); - String methodSignature = "([" + jvmPrimitiveType.getAsmType() + ")" + iterator.getDescriptor(); - v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature); - return StackValue.onStack(iterator.getAsmType()); - } + + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); + ClassDescriptor arrayClass = KotlinBuiltIns.getInstance().getPrimitiveArrayClassDescriptor(primitiveType); + if (containingDeclaration.equals(arrayClass)) { + String iteratorDesc = asmDescByFqNameWithoutInnerClasses(new FqName("jet." + primitiveType.getTypeName() + "Iterator")); + String methodSignature = "([" + jvmPrimitiveType.getAsmType() + ")" + iteratorDesc; + v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature); + return StackValue.onStack(Type.getType(iteratorDesc)); } - throw new UnsupportedOperationException(containingDeclaration.toString()); } + + throw new UnsupportedOperationException(containingDeclaration.toString()); } } diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java index ba320c064a7..78d56c80263 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java @@ -81,7 +81,6 @@ public class JvmClassName { private final String internalName; private FqName fqName; - private String descriptor; private Type asmType; private JvmClassName(@NotNull String internalName) { @@ -101,18 +100,10 @@ public class JvmClassName { return internalName; } - @NotNull - public String getDescriptor() { - if (descriptor == null) { - descriptor = "L" + internalName + ';'; - } - return descriptor; - } - @NotNull public Type getAsmType() { if (asmType == null) { - asmType = Type.getType(getDescriptor()); + asmType = Type.getType("L" + internalName + ';'); } return asmType; }