classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Classpath build process and VM-specific issues


From: Etienne Gagnon
Subject: Re: Classpath build process and VM-specific issues
Date: Mon, 05 Apr 2004 14:27:58 -0400
User-agent: Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.6) Gecko/20040402 Debian/1.6-4

Andrew Haley wrote:
Sure.  Instead of putting a native pointer in a long or in a byte[],
you just declare a class with a single field that contains the
pointer.  Everyone who needs a pointer makes a suitably named
subclass, so they'll know what they're pointing to.

How is that more efficient than a byte array?

Here's a concrete example:


class SomeRandomLibraryClass
{
  static
  {
    System.loadLibrary("SomeRandomJNILibrary");
  }

  private byte[] nativePointer;

  private native byte[] initNativeData(...);
  private native void someNativeMethod(byte[] nativePointer, ...);

  public SomeRandomLibraryClass(...)
  {
    ...
    nativePointer = initNativeData(...);
  }

  public void someMethod(...)
  {
    someNativeMethod(nativePointer, ...)  /**  THE REAL CALL **/
  }
}

In the C code, we'll have:

JNIEXPORT void JNICALL
Java_somepackage_someNativeMethod
  (JNIEnv *env, jobject this, jbyteArray nativePointer, ...)

{
  void *ptr;
  (*env)->GetByteArrayRegion(env, nativePointer, 0, sizeof(void *), (jbyte *) 
&ptr);
  ...
  /* do whatever with ptr */
  ...
}

So, how is your opaque type more efficient (and portable)?

Etienne

--
Etienne M. Gagnon, Ph.D.             http://www.info.uqam.ca/~egagnon/
SableVM:                                       http://www.sablevm.org/
SableCC:                                       http://www.sablecc.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]