Class NativeRegistry


  • public final class NativeRegistry
    extends Object
    Thread-safe registry mapping owner.name+descriptor keys to native-method handlers.
    • Constructor Detail

      • NativeRegistry

        public NativeRegistry()
        Creates an empty registry.
    • Method Detail

      • register

        public void register​(String owner,
                             String name,
                             String descriptor,
                             NativeMethodHandler handler)
        Registers a handler for the identified method.
        Parameters:
        owner - internal name of the declaring class
        name - the method name
        descriptor - the method descriptor
        handler - the handler to invoke for the method
      • register

        public void register​(String key,
                             NativeMethodHandler handler)
        Registers a handler under a precomputed method key.
        Parameters:
        key - a key produced by methodKey
        handler - the handler to invoke for the method
      • hasHandler

        public boolean hasHandler​(String owner,
                                  String name,
                                  String descriptor)
        Checks whether a handler is registered for the identified method.
        Parameters:
        owner - internal name of the declaring class
        name - the method name
        descriptor - the method descriptor
        Returns:
        true if a handler is registered
      • hasHandler

        public boolean hasHandler​(MethodEntry method)
        Checks whether a handler is registered for the given method.
        Parameters:
        method - the method to look up
        Returns:
        true if a handler is registered
      • getHandler

        public NativeMethodHandler getHandler​(String owner,
                                              String name,
                                              String descriptor)
        Looks up the handler for the identified method.
        Parameters:
        owner - internal name of the declaring class
        name - the method name
        descriptor - the method descriptor
        Returns:
        the registered handler
        Throws:
        IllegalArgumentException - if no handler is registered
      • execute

        public ConcreteValue execute​(String owner,
                                     String name,
                                     String descriptor,
                                     ObjectInstance receiver,
                                     ConcreteValue[] args,
                                     NativeContext context)
                              throws NativeException
        Runs the registered handler for the identified method.
        Parameters:
        owner - internal name of the declaring class
        name - the method name
        descriptor - the method descriptor
        receiver - the receiver instance, or null for static methods
        args - the argument values
        context - the native execution environment
        Returns:
        the handler's result, or null for void
        Throws:
        NativeException - if the handler raises a guest exception
        IllegalArgumentException - if no handler is registered
      • methodKey

        public static String methodKey​(String owner,
                                       String name,
                                       String descriptor)
        Builds the registry key for the identified method.
        Parameters:
        owner - internal name of the declaring class
        name - the method name
        descriptor - the method descriptor
        Returns:
        the composite key
      • methodKey

        public static String methodKey​(MethodEntry method)
        Builds the registry key for the given method.
        Parameters:
        method - the method to key
        Returns:
        the composite key
      • registerProvider

        public void registerProvider​(NativeHandlerProvider provider)
        Lets the given provider register its handlers with this registry.
        Parameters:
        provider - the handler contributor
      • registerDefaults

        public void registerDefaults()
        Registers all built-in handler families covering the core JDK surface.