tblair / native-intercept Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/native-intercept
Automatically exported from code.google.com/p/native-intercept
NativeIntercept is a small library that uses bytecode generation to instrument classes with native methods to allow those methods to be handled by java code rather than native code. Notes: - This is currently pre-alpha. It's had limited testing and mostly works, but there's probably a lot of bugs. - This requires Java 1.6 or higher. While the Java agent functionality was available in Java 1.5, this library uses the Instrumentation#setNativePrefix method which was added in 1.6. - This library uses the excellent ASM bytecode manipulation library. That project can be found at: http://asm.ow2.org This also uses the JarJar library to package the version of asm that's expected in the distribution jar without conflicting with another version of the library that may be on the classpath. That project can be found at: http://code.google.com/p/jarjar/
Hello,
Can anyone please put a guide how to use the native-intercept ?
Thanks
Original issue reported on code.google.com by [email protected]
on 12 Jun 2012 at 3:15
What steps will reproduce the problem?
1. Create class with "native void someMethod(int x)".
2. Intercept native calls for the class from #1.
3. Invoke someMethod().
What is the expected output? What do you see instead?
Expected to have InvocationHandler invoked for the method. I got an
exception instead:
Exception in thread "main" java.lang.IllegalStateException: Unexpected
exception thrown in interceptor
at com.google.nativeproxy.ContainsNative.nativeMethod_V_I(ContainsNative.java)
at com.google.nativeproxy.NpDemo.run(NpDemo.java:27)
at com.google.nativeproxy.NpDemo.main(NpDemo.java:34)
Caused by: java.lang.NoClassDefFoundError: I
... 3 more
Caused by: java.lang.ClassNotFoundException: I
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
... 3 more
What version of the product are you using? On what operating system?
0.1.1-pre-alpha
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 27 Jul 2009 at 11:19
What steps will reproduce the problem?
1. Subclass a class declaring a native.
2. Invoke the native through the subclass.
3.
What is the expected output? What do you see instead?
Expected to have InvocationHandler invoked for native method. Got an
exception instead:
java.lang.IllegalStateException: Attempt to intercept non-existent native
method
at org.synth.intercept.NativeInvocationHandler.findMethod(Unknown Source)
at org.synth.intercept.NativeInvocationHandler.handleObject(Unknown Source)
...
What version of the product are you using? On what operating system?
0.1.1 prealpha
Please provide any additional information below.
It looks like NativeInvocationHandler.findMethod should keep looking at
parent classes if it can't find a declared method.
Original issue reported on code.google.com by [email protected]
on 27 Jul 2009 at 11:26
Hello,
this is my test program:
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import org.synth.intercept.NativeInterceptor;
public class Test {
public static void main(String[] args) throws ClassNotFoundException {
NativeInterceptor.intercept(Class.forName("java.net.PlainSocketImpl"),
new MyInvocationHandler());
}
static class MyInvocationHandler implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("Proxy: " + proxy + "\nMethod: " + method + "\n");
return null;
}
}
}
and this is how I'm invoking it (CLASSPATH is set, tools.jar is added too):
java -javaagent:../lib/native-interceptor-0.1.3-alpha.jar Test
However I get following exception:
Exception in thread "main" java.lang.IllegalStateException: Cannot instrument
class to intercept native methods...see documentation for causes
at org.synth.intercept.NativeInterceptor.intercept(NativeInterceptor.java:58)
at org.synth.intercept.NativeInterceptor.intercept(NativeInterceptor.java:29)
at Test.main(Test.java:13)
I checked the code (from SVN, not sure if it's same as in 0.1.3-alpha) and this
exception is thrown if following check fails:
if (type.getAnnotation(HasNatives.class) == null)
throw new ...
Is it neccessary to use @HasNative annotation?
Thank you.
Original issue reported on code.google.com by [email protected]
on 8 Jun 2011 at 3:52
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.