FW: Extending java lang classes
Simmen David
simmen at inf.ethz.ch
Fri Jun 1 08:09:56 PDT 2012
-----Original Message-----
From: Simmen David
Sent: Friday, June 01, 2012 2:57 PM
To: 'Volker Simonis'
Subject: RE: FW: Extending java lang classes
I did so. But just now I found the solution One has to extend jdk/make/java/java/mapfile-vers
MfG & thx david
-----Original Message-----
From: Volker Simonis [mailto:volker.simonis at gmail.com]
Sent: Friday, June 01, 2012 2:55 PM
To: Simmen David
Cc: jdk7-dev at openjdk.java.net
Subject: Re: FW: Extending java lang classes
Are you sure you really compiled and are using a new version of libjava.so which contains 'Java_java_lang_Object_get42'.
On Unix you can check this by doing:
nm <jdk_path>/jre/lib/amd64/libjava.so | grep Java_java_lang_Object_get42
Volker
On Fri, Jun 1, 2012 at 2:24 PM, Simmen David <simmen at inf.ethz.ch> wrote:
> Hope this doesn't end as a repost but ain't sure it was sent the first
> time
>
> From: Simmen David
> Sent: Friday, June 01, 2012 1:58 PM
> To: 'jdk7-dev at openjdk.java.net'
> Subject: Extending java lang classes
>
> Hi
>
> Out of a personal interest I wanted to add an additional method to java.lang.Object which returns the integer 42.
>
> So far I added to Object.java the method:
> public final native int get42();
>
> in Object.c:
> JNIEXPORT jint JNICALL
> Java_java_lang_Object_get42(JNIEnv *env, jobject this) {
> if (this == NULL) {
> JNU_ThrowNullPointerException(env,
> NULL);
> return 0;
> } else {
> return 42;
> }
> }
>
> And in java_lang_Object.h you can see the generated declaration by javah:
> JNIEXPORT jint JNICALL Java_java_lang_Object_get42
> (JNIEnv *, jobject);
>
> It all com[piles and so but when I try to call the method I get:
> Exception in thread "main" java.lang.UnsatisfiedLinkError:
> java.lang.Object.get42()I
> at java.lang.Object.get42(Native Method)
> at Main.main(Main.java:13)
>
> I found out that it tries to look it up at runtime and not like for example getClass at startup but I didn't find the place where to specify that it should load it at startup.
> So what am I missing here so that it runs?
>
> MfG David
>
>
>
More information about the jdk7-dev
mailing list