Class Ek9ClassWriter
Standard ClassWriter.COMPUTE_FRAMES uses ClassLoader to find common superclasses when computing stack map frames. This fails when generating multiple classes in the same compilation unit because referenced classes aren't on classpath yet.
This custom writer uses a type hierarchy map (built from ISymbol data) to find actual common superclasses. This is essential for function delegate polymorphism: when if/else branches assign different concrete functions (e.g., UpperProcessor, LowerProcessor) to a variable of abstract type (Processor), ASM needs to know the actual common superclass (Processor) rather than defaulting to Object.
For exception types, uses java/lang/Throwable as the common superclass. For types not in the hierarchy map, defaults to java/lang/Object.
-
Field Summary
Fields inherited from class org.objectweb.asm.ClassWriter
COMPUTE_FRAMES, COMPUTE_MAXSFields inherited from class org.objectweb.asm.ClassVisitor
api, cv -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringgetCommonSuperClass(String type1, String type2) Override getCommonSuperClass to use EK9's type hierarchy from ISymbol data.byte[]THE chokepoint that makes a zero-length JVM exception-table entry impossible to emit (seeSafeExceptionTableMethodVisitor).Methods inherited from class org.objectweb.asm.ClassWriter
getClassLoader, hasFlags, newClass, newConst, newConstantDynamic, newField, newHandle, newHandle, newInvokeDynamic, newMethod, newMethodType, newModule, newNameType, newPackage, newUTF8, setFlags, visit, visitAnnotation, visitAttribute, visitEnd, visitField, visitInnerClass, visitMethod, visitModule, visitNestHost, visitNestMember, visitOuterClass, visitPermittedSubclass, visitRecordComponent, visitSource, visitTypeAnnotationMethods inherited from class org.objectweb.asm.ClassVisitor
getDelegate
-
Constructor Details
-
Ek9ClassWriter
-
-
Method Details
-
toByteArray
public byte[] toByteArray()THE chokepoint that makes a zero-length JVM exception-table entry impossible to emit (seeSafeExceptionTableMethodVisitor). ASM'sClassWriter.visitMethodisfinalso the wrapper cannot be installed there; instead this filters the finished class on the way out. Every backendClassWriteris anEk9ClassWriter, so this one override covers every generated class regardless of which generator produced it or how it registered its exception handlers.See
SafeExceptionTableMethodVisitor.filterDegenerateExceptionTables(byte[])for the copy pass that drops any exception-table entry whose start and end labels resolve to the same offset. For valid code (no degenerate range) the copy is faithful and normalisation-equivalent — the filter only ever removes would-be-invalid entries.- Overrides:
toByteArrayin classorg.objectweb.asm.ClassWriter
-
getCommonSuperClass
Override getCommonSuperClass to use EK9's type hierarchy from ISymbol data. Walks up both type hierarchies to find the first common ancestor.- Overrides:
getCommonSuperClassin classorg.objectweb.asm.ClassWriter- Parameters:
type1- First type (internal name, e.g., "module/UpperProcessor")type2- Second type (internal name, e.g., "module/LowerProcessor")- Returns:
- Common superclass internal name (e.g., "module/Processor")
-