diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java index 60d88c9cf7be..def52c8b6cec 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java @@ -17,6 +17,7 @@ */ package io.ballerina.runtime.internal.values; +import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BString; @@ -86,4 +87,7 @@ public abstract BObject createObjectValue(String objectTypeName, Scheduler sched public abstract BError createErrorValue(String errorTypeName, BString message, BError cause, Object details) throws BError; + + public abstract Type getAnonType(int typeHash, String typeShape) throws BError; + } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmConstants.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmConstants.java index f1c0403676af..11ed2e247785 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmConstants.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmConstants.java @@ -303,6 +303,7 @@ public class JvmConstants { public static final String CREATE_RECORD_VALUE = "createRecordValue"; public static final String CREATE_OBJECT_VALUE = "createObjectValue"; public static final String CREATE_ERROR_VALUE = "createErrorValue"; + public static final String GET_ANON_TYPE = "getAnonType"; // strand data related constants public static final String STRAND = "strand"; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java index a2f2146ce9fe..7228237aafe2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java @@ -455,13 +455,14 @@ private void generateModuleClasses(BIRPackage module, Map jarEnt ClassWriter cw = new BallerinaClassWriter(COMPUTE_FRAMES); AsyncDataCollector asyncDataCollector = new AsyncDataCollector(moduleClass); boolean isInitClass = Objects.equals(moduleClass, moduleInitClass); - JvmTypeGen jvmTypeGen = new JvmTypeGen(stringConstantsGen); + JvmTypeGen jvmTypeGen = new JvmTypeGen(stringConstantsGen, module.packageID); JvmCastGen jvmCastGen = new JvmCastGen(symbolTable, jvmTypeGen); LambdaGen lambdaGen = new LambdaGen(this, jvmCastGen); if (isInitClass) { cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, moduleClass, null, VALUE_CREATOR, null); JvmCodeGenUtil.generateDefaultConstructor(cw, VALUE_CREATOR); jvmTypeGen.generateUserDefinedTypeFields(cw, module.typeDefs); + jvmTypeGen.generateGetAnonTypeMethod(cw, module.typeDefs, moduleInitClass); jvmTypeGen.generateValueCreatorMethods(cw, module.typeDefs, module.packageID, moduleInitClass, symbolTable, asyncDataCollector); // populate global variable to class name mapping and generate them diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java index c87cef4e3f16..102612fc57b1 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java @@ -29,8 +29,10 @@ import org.wso2.ballerinalang.compiler.bir.codegen.internal.BIRVarToJVMIndexMap; import org.wso2.ballerinalang.compiler.bir.codegen.internal.ScheduleFunctionInfo; import org.wso2.ballerinalang.compiler.bir.model.BIRNode.BIRTypeDefinition; +import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.semantics.analyzer.IsAnydataUniqueVisitor; import org.wso2.ballerinalang.compiler.semantics.analyzer.IsPureTypeUniqueVisitor; +import org.wso2.ballerinalang.compiler.semantics.analyzer.TypeHashVisitor; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BAttachedFunction; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BObjectTypeSymbol; @@ -66,6 +68,7 @@ import org.wso2.ballerinalang.util.Flags; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -91,6 +94,7 @@ import static org.objectweb.asm.Opcodes.IFEQ; import static org.objectweb.asm.Opcodes.IFNE; import static org.objectweb.asm.Opcodes.IFNONNULL; +import static org.objectweb.asm.Opcodes.ILOAD; import static org.objectweb.asm.Opcodes.INSTANCEOF; import static org.objectweb.asm.Opcodes.INVOKEINTERFACE; import static org.objectweb.asm.Opcodes.INVOKESPECIAL; @@ -133,6 +137,7 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.FUNCTION_TYPE_IMPL; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.FUTURE_TYPE_IMPL; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.FUTURE_VALUE; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.GET_ANON_TYPE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.HANDLE_TYPE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.HANDLE_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.INTEGER_TYPE; @@ -195,6 +200,7 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.XML_TYPE_IMPL; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.XML_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmValueGen.NAME_HASH_COMPARATOR; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmValueGen.TYPE_HASH_COMPARATOR; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmValueGen.createDefaultCase; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmValueGen.getTypeDescClassName; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmValueGen.getTypeValueClassName; @@ -209,11 +215,15 @@ public class JvmTypeGen { private final IsPureTypeUniqueVisitor isPureTypeUniqueVisitor; private final IsAnydataUniqueVisitor isAnydataUniqueVisitor; private final JvmBStringConstantsGen stringConstantsGen; + private final TypeHashVisitor typeHashVisitor; + private final PackageID packageID; - public JvmTypeGen(JvmBStringConstantsGen stringConstantsGen) { + public JvmTypeGen(JvmBStringConstantsGen stringConstantsGen, PackageID packageID) { this.stringConstantsGen = stringConstantsGen; + this.packageID = packageID; isPureTypeUniqueVisitor = new IsPureTypeUniqueVisitor(); isAnydataUniqueVisitor = new IsAnydataUniqueVisitor(); + typeHashVisitor = new TypeHashVisitor(); } /** @@ -501,6 +511,75 @@ static List