Class BytecodeNormalizer

java.lang.Object
org.ek9lang.compiler.backend.jvm.BytecodeNormalizer

public final class BytecodeNormalizer extends Object
Normalizes JVM bytecode output from javap for stable test comparisons.

Normalization removes fragile elements like constant pool indices, line number tables, and debug information while preserving essential instruction sequences and method signatures.

This utility is specifically designed for testing bytecode generation by enabling reliable comparison of expected vs actual bytecode output.

  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    normalize(byte[] classBytes)
    Normalize bytecode from .class file bytes with default settings.
    static String
    normalize(byte[] classBytes, boolean includeLineNumberTable, boolean includeSourceDebugExtension)
    Normalize bytecode from .class file bytes with configuration options.
    static String
    rawJavap(byte[] classBytes)
    The RAW javap -c -p -l -v output for the given class bytes, with no normalization at all.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • normalize

      public static String normalize(byte[] classBytes)
      Normalize bytecode from .class file bytes with default settings. Includes debug information (LineNumberTable and SourceDebugExtension).
      Parameters:
      classBytes - Compiled .class file bytes
      Returns:
      Normalized bytecode text suitable for test comparison
      Throws:
      RuntimeException - if normalization fails
    • normalize

      public static String normalize(byte[] classBytes, boolean includeLineNumberTable, boolean includeSourceDebugExtension)
      Normalize bytecode from .class file bytes with configuration options.
      Parameters:
      classBytes - Compiled .class file bytes
      includeLineNumberTable - Include LineNumberTable debug information
      includeSourceDebugExtension - Include SourceDebugExtension (SMAP) information
      Returns:
      Normalized bytecode text suitable for test comparison
      Throws:
      RuntimeException - if normalization fails
    • rawJavap

      public static String rawJavap(byte[] classBytes)
      The RAW javap -c -p -l -v output for the given class bytes, with no normalization at all.

      This is the shared entry point for callers that want to slice ONE section out of javap's output (the @DEBUG directive, via JavapSectionExtractor) rather than the whole-class normalized form normalize(byte[]) produces. Keeping the temp-file + process handling in one place means @DEBUG does not re-derive the javap invocation.

      Parameters:
      classBytes - Compiled .class file bytes
      Returns:
      Raw javap output
      Throws:
      RuntimeException - if javap execution fails