Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native methods: Support "import" property to ensure needed classes are initialized #360

Open
jvilk opened this issue Feb 13, 2015 · 3 comments

Comments

@jvilk
Copy link
Member

jvilk commented Feb 13, 2015

Our need to make method calls asynchronous makes writing native methods quite messy, as we have to distribute initialize checks through them. For "hot" native methods, we often have two paths through the method: a "slow" path that performs initialization, and a "fast" path that can perform the method synchronously. The "slow" path returns undefined, and the "fast" path returns the JVM method's return value.

In addition, native methods are populated with calls to the classloader to retrieve ClassData objects.

A simple change to our native method structure will let native methods for a particular class "import" classes into a structure on the native method object passed to the VM, eliminating the slow path and the need to call the classloader for statically determinable classes.

Further details will be posted when I've thought further on the syntax.

@ghost
Copy link

ghost commented Dec 20, 2015

Can I define natives in VM callback function? such as,

new doppio.JVM({
  bootstrapClasspath: ['/sys/vendor/java_home/classes'],
  classpath: ['/sys'],
  javaHomePath: '/sys/vendor/java_home',
  extractionPath: '/tmp',
  nativeClasspath: ['/sys/natives'],
  assertionsEnabled: false
}, function(err, jvmObject) {
    registerNatives({
      'com/example/Test': {
        'consoleLog(Ljava/lang/String;)V': function(thread, arg0) {
           console.log(arg0.toString());
        }
      }
    });
});

@jvilk
Copy link
Member Author

jvilk commented Dec 20, 2015

@bertung yup, you sure can. There's no strict requirement to use separate JS files on the native classpath like I do for the built-in natives; those are more of a convenience, as DoppioJVM re-evals those files with each run to prevent state from being shared across JVM invocations.

@ghost
Copy link

ghost commented Dec 20, 2015

Outstanding thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant