Class NativeCallHandler


public class NativeCallHandler extends Object
Handler for native calls instrumented by ClassInstrumentor.

Native Calls can either be instrumented as no-op calls (returning a default value or 0 or null) or throw an exception. This helper class helps maintain a list of exemptions to indicates which native calls should be no-op and never throw.

  • Constructor Details

    • NativeCallHandler

      public NativeCallHandler(@Nonnull File exemptionsFile, boolean writeExemptions, boolean throwOnNatives) throws IOException
      Initializes the native calls handler.
      exemptionsFile - The exemptions file to read from and/or to generate.
      writeExemptions - When true, native calls are added to the exemption list.
      throwOnNatives - Whether native calls should throw by default unless their signature is listed in the exemption list. When false, all native calls become no-op.
      IOException - if there's an issue reading an existing exemption list.
  • Method Details

    • writeExemptionsList

      public void writeExemptionsList() throws IOException
    • logNativeCall

      public void logNativeCall(@Nonnull String descriptor)
      Adds the method description to the native call exemption list if writeExemptions is set.
    • shouldThrow

      public boolean shouldThrow(@Nonnull String descriptor)
      Returns whether the ClassInstrumentor should generate an exception or a no-op bytecode.
    • getExceptionMessage

      public String getExceptionMessage(@Nonnull String descriptor, @Nonnull String className, @Nonnull String methodName)
      Returns the detailed message to be used by the ClassInstrumentor in the generated bytecode.
      descriptor - The ASM descriptor as it should be written in the exemption file.
      className - The fully qualified class name, used for the user description.
      methodName - The method name, used for the user description.