ArrayElements() when transferring array of
* primitives from/to C. This is an optimization to avoid copying
* memory and must be used carefully. It is ok to be used in
* MoveMemory() and memmove() natives.
*/
CRITICAL,
/**
* Indicate that the associated C local variable for a native method
* parameter should be initialized with zeros.
*/
INIT,
/**
* Indicate that the parameter is a pointer.
*/
POINTER_ARG,
/**
* Indicate that a structure parameter should be passed by value
* instead of by reference. This dereferences the parameter by
* prepending *. The parameter must not be NULL.
*/
BY_VALUE,
/**
* Indicate that GetStringChars()should be used instead of
* GetStringUTFChars() to get the characters of a java.lang.String
* passed as a parameter to native methods.
*/
UNICODE,
/**
* Indicate that the parameter of a native method is the sentinel
* (last parameter of a variable argument C function). The generated
* code is always the literal NULL. Some compilers expect the sentinel
* to be the literal NULL and output a warning if otherwise.
*/
SENTINEL,
/**
* Indicate that the native parameter is a C# managed object.
*/
CS_OBJECT,
} Callback.java 0000664 0000000 0000000 00000022401 11426650065 0033351 0 ustar 00root root 0000000 0000000 hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime /*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
/**
* Instances of this class represent entry points into Java which can be invoked
* from operating system level callback routines.
*
* IMPORTANT: A callback is only valid when invoked on the thread which created
* it. The results are undefined (and typically bad) when a callback is passed
* out to the operating system (or other code) in such a way that the callback
* is called from a different thread.
*/
public class Callback {
Object object;
String method, signature;
int argCount;
long /* int */ address, errorResult;
boolean isStatic, isArrayBased;
static final String PTR_SIGNATURE = "J"; /* C.PTR_SIZEOF == 4 ? "I" : "J"; */
static final String SIGNATURE_0 = getSignature(0);
static final String SIGNATURE_1 = getSignature(1);
static final String SIGNATURE_2 = getSignature(2);
static final String SIGNATURE_3 = getSignature(3);
static final String SIGNATURE_4 = getSignature(4);
static final String SIGNATURE_N = "([" + PTR_SIGNATURE + ")" + PTR_SIGNATURE;
/**
* Constructs a new instance of this class given an object to send the
* message to, a string naming the method to invoke and an argument count.
* Note that, if the object is an instance of Class
it is
* assumed that the method is a static method on that class.
*
* @param object
* the object to send the message to
* @param method
* the name of the method to invoke
* @param argCount
* the number of arguments that the method takes
*/
public Callback(Object object, String method, int argCount) {
this(object, method, argCount, false);
}
/**
* Constructs a new instance of this class given an object to send the
* message to, a string naming the method to invoke, an argument count and a
* flag indicating whether or not the arguments will be passed in an array.
* Note that, if the object is an instance of Class
it is
* assumed that the method is a static method on that class.
*
* @param object
* the object to send the message to
* @param method
* the name of the method to invoke
* @param argCount
* the number of arguments that the method takes
* @param isArrayBased
* true
if the arguments should be passed in an
* array and false otherwise
*/
public Callback(Object object, String method, int argCount, boolean isArrayBased) {
this(object, method, argCount, isArrayBased, 0);
}
/**
* Constructs a new instance of this class given an object to send the
* message to, a string naming the method to invoke, an argument count, a
* flag indicating whether or not the arguments will be passed in an array
* and a value to return when an exception happens. Note that, if the object
* is an instance of Class
it is assumed that the method is a
* static method on that class.
*
* @param object
* the object to send the message to
* @param method
* the name of the method to invoke
* @param argCount
* the number of arguments that the method takes
* @param isArrayBased
* true
if the arguments should be passed in an
* array and false otherwise
* @param errorResult
* the return value if the java code throws an exception
*/
public Callback(Object object, String method, int argCount, boolean isArrayBased, int /* long */errorResult) {
/* Set the callback fields */
this.object = object;
this.method = method;
this.argCount = argCount;
this.isStatic = object instanceof Class>;
this.isArrayBased = isArrayBased;
this.errorResult = errorResult;
/* Inline the common cases */
if (isArrayBased) {
signature = SIGNATURE_N;
} else {
switch (argCount) {
case 0:
signature = SIGNATURE_0;
break; //$NON-NLS-1$
case 1:
signature = SIGNATURE_1;
break; //$NON-NLS-1$
case 2:
signature = SIGNATURE_2;
break; //$NON-NLS-1$
case 3:
signature = SIGNATURE_3;
break; //$NON-NLS-1$
case 4:
signature = SIGNATURE_4;
break; //$NON-NLS-1$
default:
signature = getSignature(argCount);
}
}
/* Bind the address */
address = bind(this, object, method, signature, argCount, isStatic, isArrayBased, errorResult);
}
/**
* Allocates the native level resources associated with the callback. This
* method is only invoked from within the constructor for the argument.
*
* @param callback
* the callback to bind
* @param object
* the callback's object
* @param method
* the callback's method
* @param signature
* the callback's method signature
* @param argCount
* the callback's method argument count
* @param isStatic
* whether the callback's method is static
* @param isArrayBased
* whether the callback's method is array based
* @param errorResult
* the callback's error result
*/
static native synchronized long /* int */ bind(Callback callback, Object object, String method, String signature, int argCount, boolean isStatic, boolean isArrayBased,
long /* int */errorResult);
/**
* Releases the native level resources associated with the callback, and
* removes all references between the callback and other objects. This helps
* to prevent (bad) application code from accidentally holding onto
* extraneous garbage.
*/
public void dispose() {
if (object == null)
return;
unbind(this);
object = method = signature = null;
address = 0;
}
/**
* Returns the address of a block of machine code which will invoke the
* callback represented by the receiver.
*
* @return the callback address
*/
public long /* int */getAddress() {
return address;
}
/**
* Returns the SWT platform name.
*
* @return the platform name of the currently running SWT
*/
public static native String getPlatform();
/**
* Returns the number of times the system has been recursively entered
* through a callback.
*
* Note: This should not be called by application code.
*
*
* @return the entry count
*
* @since 2.1
*/
public static native int getEntryCount();
static String getSignature(int argCount) {
String signature = "("; //$NON-NLS-1$
for (int i = 0; i < argCount; i++)
signature += PTR_SIGNATURE;
signature += ")" + PTR_SIGNATURE; //$NON-NLS-1$
return signature;
}
/**
* Indicates whether or not callbacks which are triggered at the native
* level should cause the messages described by the matching
* Callback
objects to be invoked. This method is used to
* safely shut down SWT when it is run within environments which can
* generate spurious events.
*
* Note: This should not be called by application code.
*
*
* @param enable
* true if callbacks should be invoked
*/
public static final native synchronized void setEnabled(boolean enable);
/**
* Returns whether or not callbacks which are triggered at the native level
* should cause the messages described by the matching Callback
* objects to be invoked. This method is used to safely shut down SWT when
* it is run within environments which can generate spurious events.
*
* Note: This should not be called by application code.
*
*
* @return true if callbacks should not be invoked
*/
public static final native synchronized boolean getEnabled();
/**
* Immediately wipes out all native level state associated with all
* callbacks.
*
* WARNING: This operation is extremely dangerous, and
* should never be performed by application code.
*
*/
public static final native synchronized void reset();
/**
* Releases the native level resources associated with the callback.
*
* @see #dispose
*/
static final native synchronized void unbind(Callback callback);
}
ClassFlag.java 0000664 0000000 0000000 00000002562 11426650065 0033522 0 ustar 00root root 0000000 0000000 hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime /*******************************************************************************
* Copyright (c) 2009 Progress Software, Inc.
* Copyright (c) 2004, 2008 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
/**
*
* @author Hiram Chirino
*/
public enum ClassFlag {
/**
* Indicate that the item should not be generated. For example,
* custom natives are coded by hand.
*/
CLASS_SKIP,
/**
* Indicate that the platform source is in C++
*/
CPP,
/**
* Indicate that this class will define a structure
*/
STRUCT,
/**
* Indicate that structure name is a typedef (It should
* not be prefixed with 'struct' to reference it.)
*/
TYPEDEF,
/**
* Indicate that the struct should get zeroed out before
* setting any of it's fields. Comes in handy when
* you don't map all the struct fields to java fields but
* still want the fields that are not mapped initialized.
*/
ZERO_OUT,
} FieldFlag.java 0000664 0000000 0000000 00000002062 11426650065 0033473 0 ustar 00root root 0000000 0000000 hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime /*******************************************************************************
* Copyright (c) 2009 Progress Software, Inc.
* Copyright (c) 2004, 2008 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
/**
*
* @author Hiram Chirino
*/
public enum FieldFlag {
/**
* Indicate that the item should not be generated. For example,
* custom natives are coded by hand.
*/
FIELD_SKIP,
/**
* Indicate that the field represents a constant or global
* variable. It is expected that the java field will be declared
* static.
*/
CONSTANT,
/**
* Indicate that the field is a pointer.
*/
POINTER_FIELD,
} hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/JniArg.java 0000664 0000000 0000000 00000001510 11426650065 0033104 0 ustar 00root root 0000000 0000000 /*******************************************************************************
* Copyright (c) 2009 Progress Software, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
/**
*
*/
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
@Target({PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface JniArg {
ArgFlag[] flags() default {};
String cast() default "";
}
JniClass.java 0000664 0000000 0000000 00000001516 11426650065 0033367 0 ustar 00root root 0000000 0000000 hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime /*******************************************************************************
* Copyright (c) 2009 Progress Software, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
/**
*
*/
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
@Target({TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface JniClass {
ClassFlag[] flags() default {};
String conditional() default "";
}
JniField.java 0000664 0000000 0000000 00000001716 11426650065 0033347 0 ustar 00root root 0000000 0000000 hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime /*******************************************************************************
* Copyright (c) 2009 Progress Software, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
/**
*
* @author Hiram Chirino
*/
@Target({FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface JniField {
String cast() default "";
String accessor() default "";
String conditional() default "";
FieldFlag[] flags() default {};
}
JniMethod.java 0000664 0000000 0000000 00000002130 11426650065 0033533 0 ustar 00root root 0000000 0000000 hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime /*******************************************************************************
* Copyright (c) 2009 Progress Software, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
/**
*
* @author Hiram Chirino
*/
@Target({METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface JniMethod {
String cast() default "";
// Pointer pointer() default Pointer.DETERMINE_FROM_CAST;
String accessor() default "";
MethodFlag[] flags() default {};
String copy() default "";
String conditional() default "";
JniArg[] callbackArgs() default {};
}
hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java0000775 0000000 0000000 00000027117 11426650065 0033354 0 ustar 00root root 0000000 0000000 /*******************************************************************************
* Copyright (c) 2009 Progress Software, Inc.
* Copyright (c) 2000, 2009 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.regex.Pattern;
/**
* Used to optionally extract and load a JNI library.
*
* It will search for the library in order at the following locations:
*
* - in the custom library path: If the "library.${name}.path" System property is set to a directory
*
* - "${name}-${version}" if the version can be determined.
*
- "${name}"
*
* - system library path: This is where the JVM looks for JNI libraries by default.
*
* - "${name}-${version}" if the version can be determined.
*
- "${name}"
*
* - classpath path: If the JNI library can be found on the classpath, it will get extracted
* and and then loaded. This way you can embed your JNI libraries into your packaged JAR files.
* They are looked up as resources in this order:
*
* - "META-INF/native/${platform}/${library}" : Store your library here if you want to embed more
* than one platform JNI library in the jar.
*
- "META-INF/native/${library}": Store your library here if your JAR is only going to embedding one
* platform library.
*
* The file extraction is attempted until it succeeds in the following directories.
*
* - The directory pointed to by the "library.${name}.path" System property (if set)
*
- a temporary directory (uses the "java.io.tmpdir" System property)
*
*
*
* where:
*
* - "${name}" is the name of library
*
- "${version}" is the value of "library.${name}.version" System property if set.
* Otherwise it is set to the ImplementationVersion property of the JAR's Manifest
* - "${os}" is your operating system, for example "osx", "linux", or "windows"
* - "${bit-model}" is "64" if the JVM process is a 64 bit process, otherwise it's "32" if the
* JVM is a 32 bit process
* - "${platform}" is "${os}${bit-model}", for example "linux32" or "osx64"
* - "${library}": is the normal jni library name for the platform. For example "${name}.dll" on
* windows, "lib${name}.jnilib" on OS X, and "lib${name}.so" on linux
*
*
* @author Hiram Chirino
*/
public class Library {
static final String SLASH = System.getProperty("file.separator");
final private String name;
final private String version;
final private ClassLoader classLoader;
private boolean loaded;
public Library(String name) {
this(name, null, null);
}
public Library(String name, Class> clazz) {
this(name, version(clazz), clazz.getClassLoader());
}
public Library(String name, String version) {
this(name, version, null);
}
public Library(String name, String version, ClassLoader classLoader) {
if( name == null ) {
throw new IllegalArgumentException("name cannot be null");
}
this.name = name;
this.version = version;
this.classLoader= classLoader;
}
private static String version(Class> clazz) {
try {
return clazz.getPackage().getImplementationVersion();
} catch (Throwable e) {
}
return null;
}
public String getOperatingSystem() {
String name = System.getProperty("os.name").toLowerCase().trim();
if( name.startsWith("linux") ) {
return "linux";
}
if( name.startsWith("mac os x") ) {
return "osx";
}
if( name.startsWith("win") ) {
return "windows";
}
return name.replaceAll("\\W+", "_");
}
public String getPlatform() {
return getOperatingSystem()+getBitModel();
}
protected static int getBitModel() {
String prop = System.getProperty("sun.arch.data.model");
if (prop == null) {
prop = System.getProperty("com.ibm.vm.bitmode");
}
if( prop!=null ) {
return Integer.parseInt(prop);
}
return -1; // we don't know..
}
/**
*
*/
synchronized public void load() {
if( loaded ) {
return;
}
doLoad();
loaded = true;
}
private void doLoad() {
/* Perhaps a custom version is specified */
String version = System.getProperty("library."+name+".version");
if (version == null) {
version = this.version;
}
ArrayList errors = new ArrayList();
/* Try loading library from a custom library path */
String customPath = System.getProperty("library."+name+".path");
if (customPath != null) {
if( version!=null && load(errors, file(customPath, map(name + "-" + version))) )
return;
if( load(errors, file(customPath, map(name))) )
return;
}
/* Try loading library from java library path */
if( version!=null && load(errors, name + "-" + version) )
return;
if( load(errors, name ) )
return;
/* Try extracting the library from the jar */
if( classLoader!=null ) {
if( exractAndLoad(errors, version, customPath, getPlatformSpecifcResourcePath()) )
return;
if( exractAndLoad(errors, version, customPath, getOperatingSystemSpecifcResourcePath()) )
return;
// For the simpler case where only 1 platform lib is getting packed into the jar
if( exractAndLoad(errors, version, customPath, getResorucePath()) )
return;
}
/* Failed to find the library */
throw new UnsatisfiedLinkError("Could not load library. Reasons: " + errors.toString());
}
final public String getOperatingSystemSpecifcResourcePath() {
return getPlatformSpecifcResourcePath(getOperatingSystem());
}
final public String getPlatformSpecifcResourcePath() {
return getPlatformSpecifcResourcePath(getPlatform());
}
final public String getPlatformSpecifcResourcePath(String platform) {
return "META-INF/native/"+platform+"/"+map(name);
}
final public String getResorucePath() {
return "META-INF/native/"+map(name);
}
final public String getLibraryFileName() {
return map(name);
}
private boolean exractAndLoad(ArrayList errors, String version, String customPath, String resourcePath) {
URL resource = classLoader.getResource(resourcePath);
if( resource !=null ) {
String libName = name;
if( version !=null) {
libName += "-" + version;
}
if( customPath!=null ) {
// Try to extract it to the custom path...
File target = file(customPath, map(libName));
if( extract(errors, resource, target) ) {
if( load(errors, target) ) {
return true;
}
}
}
// Fall back to extracting to the tmp dir
customPath = System.getProperty("java.io.tmpdir");
File target = file(customPath, map(libName));
if( extract(errors, resource, target) ) {
if( load(errors, target) ) {
return true;
}
}
}
return false;
}
private File file(String ...paths) {
File rc = null ;
for (String path : paths) {
if( rc == null ) {
rc = new File(path);
} else {
rc = new File(rc, path);
}
}
return rc;
}
private String map(String libName) {
/*
* libraries in the Macintosh use the extension .jnilib but the some
* VMs map to .dylib.
*/
libName = System.mapLibraryName(libName);
String ext = ".dylib";
if (libName.endsWith(ext)) {
libName = libName.substring(0, libName.length() - ext.length()) + ".jnilib";
}
return libName;
}
private boolean extract(ArrayList errors, URL source, File target) {
FileOutputStream os = null;
InputStream is = null;
boolean extracting = false;
try {
if (!target.exists() || isStale(source, target) ) {
is = source.openStream();
if (is != null) {
byte[] buffer = new byte[4096];
os = new FileOutputStream(target);
extracting = true;
int read;
while ((read = is.read(buffer)) != -1) {
os.write(buffer, 0, read);
}
os.close();
is.close();
chmod("755", target);
}
}
} catch (Throwable e) {
try {
if (os != null)
os.close();
} catch (IOException e1) {
}
try {
if (is != null)
is.close();
} catch (IOException e1) {
}
if (extracting && target.exists())
target.delete();
errors.add(e.getMessage());
return false;
}
return true;
}
private boolean isStale(URL source, File target) {
if( source.getProtocol().equals("jar") ) {
// unwrap the jar protocol...
try {
String parts[] = source.getFile().split(Pattern.quote("!"));
source = new URL(parts[0]);
} catch (MalformedURLException e) {
return false;
}
}
File sourceFile=null;
if( source.getProtocol().equals("file") ) {
sourceFile = new File(source.getFile());
}
if( sourceFile!=null && sourceFile.exists() ) {
if( sourceFile.lastModified() > target.lastModified() ) {
return true;
}
}
return false;
}
private void chmod(String permision, File path) {
if (getPlatform().startsWith("windows"))
return;
try {
Runtime.getRuntime().exec(new String[] { "chmod", permision, path.getCanonicalPath() }).waitFor();
} catch (Throwable e) {
}
}
private boolean load(ArrayList errors, File lib) {
try {
System.load(lib.getPath());
return true;
} catch (UnsatisfiedLinkError e) {
errors.add(e.getMessage());
}
return false;
}
private boolean load(ArrayList errors, String lib) {
try {
System.loadLibrary(lib);
return true;
} catch (UnsatisfiedLinkError e) {
errors.add(e.getMessage());
}
return false;
}
}
MethodFlag.java 0000664 0000000 0000000 00000006272 11426650065 0033677 0 ustar 00root root 0000000 0000000 hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime /*******************************************************************************
* Copyright (c) 2009 Progress Software, Inc.
* Copyright (c) 2000, 2008 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
/**
*
* @author Hiram Chirino
*/
public enum MethodFlag {
/**
* Indicate that the item should not be generated. For example,
* custom natives are coded by hand.
*/
METHOD_SKIP,
/**
* Indicate that a native method should be looked up dynamically. It
* is useful when having a dependence on a given library is not
* desirable. The library name is specified in the *_custom.h file.
*/
DYNAMIC,
/**
* Indicate that the native method represents a constant or global
* variable instead of a function. This omits () from the generated
* code.
*/
CONSTANT_GETTER,
/**
* Indicate that the C function should be casted to a prototype
* generated from the parameters of the native method. Useful for
* variable argument C functions.
*/
CAST,
/**
* Indicate that the native is part of the Java Native Interface. For
* example: NewGlobalRef().
*/
JNI,
/**
* Indicate that the native method represents a structure global
* variable and the address of it should be returned to Java. This is
* done by prepending &.
*/
ADDRESS,
/**
* Indicate that the platform source is in C++
*/
CPP,
/**
* Indicate that the native method is a C++ constructor that allocates
* an object on the heap.
*/
CPP_NEW,
/**
* Indicate that the native method is a C++ destructor that
* deallocates an object from the heap.
*/
CPP_DELETE,
/**
* Indicate that the native method is a C# constructor that allocates
* an object on the managed (i.e. garbage collected) heap.
*/
CS_NEW,
/**
* Indicate that the native method's return value is a
* C# managed object.
*/
CS_OBJECT,
/**
* Indicate that the native method represents a setter for a field in
* an object or structure
*/
SETTER,
/**
* Indicate that the native method represents a getter for a field in
* an object or structure.
*/
GETTER,
/**
* Indicate that the native method takes 2 arguments, a collection and
* an item, and the += operator is used to add the item to the
* collection.
*/
ADDER,
/**
* Indicate that the return value is a pointer.
*/
POINTER_RETURN,
/**
* Indicate that this method will be the constant initializer for
* the class. When called, it will set all the static constant fields
* to the values defined in your platform.
*/
CONSTANT_INITIALIZER,
} NativeStats.java 0000775 0000000 0000000 00000016627 11426650065 0034142 0 ustar 00root root 0000000 0000000 hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime /*******************************************************************************
* Copyright (c) 2009 Progress Software, Inc.
* Copyright (c) 2004, 2006 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
/**
* Instructions on how to use the NativeStats tool with a standalone SWT
* example:
*
* - Compile the native libraries defining the NATIVE_STATS flag.
* - Add the following code around the sections of
* interest to dump the native calls done in that section.
*
* StatsInterface si = MyFooStatsInterface.INSTANCE;
* NativeStats stats = new NativeStats(si);
* ... // your code
* stats.diff().dump(System.out);
*
*
* - Or add the following code at a given point to dump a snapshot of
* the native calls done until that point.
*
* stats.snapshot().dump(System.out);
*
*
*
*
* @author Hiram Chirino
*/
public class NativeStats {
public interface StatsInterface {
String getNativeClass();
int functionCount();
String functionName(int ordinal);
int functionCounter(int ordinal);
}
public static class NativeFunction implements Comparable {
private final int ordinal;
private final String name;
private int counter;
public NativeFunction(int ordinal, String name, int callCount) {
this.ordinal = ordinal;
this.name = name;
this.counter = callCount;
}
void subtract(NativeFunction func) {
this.counter -= func.counter;
}
public int getCounter() {
return counter;
}
public void setCounter(int counter) {
this.counter = counter;
}
public String getName() {
return name;
}
public int getOrdinal() {
return ordinal;
}
public int compareTo(NativeFunction func) {
return func.counter - counter;
}
public void reset() {
counter=0;
}
public NativeFunction copy() {
return new NativeFunction(ordinal, name, counter);
}
}
private final HashMap> snapshot;
public NativeStats(StatsInterface... classes) {
this(Arrays.asList(classes));
}
public NativeStats(Collection classes) {
this(snapshot(classes));
}
private NativeStats(HashMap> snapshot) {
this.snapshot = snapshot;
}
public void reset() {
for (ArrayList functions : snapshot.values()) {
for (NativeFunction function : functions) {
function.reset();
}
}
}
public void update() {
for (Entry> entry : snapshot.entrySet()) {
StatsInterface si = entry.getKey();
for (NativeFunction function : entry.getValue()) {
function.setCounter( si.functionCounter(function.getOrdinal()) );
}
}
}
public NativeStats snapshot() {
NativeStats copy = copy();
copy.update();
return copy;
}
public NativeStats copy() {
HashMap> rc = new HashMap>(snapshot.size()*2);
for (Entry> entry : snapshot.entrySet()) {
ArrayList list = new ArrayList(entry.getValue().size());
for (NativeFunction function : entry.getValue()) {
list.add(function.copy());
}
rc.put(entry.getKey(), list);
}
return new NativeStats(rc);
}
public NativeStats diff() {
HashMap> rc = new HashMap>(snapshot.size()*2);
for (Entry> entry : snapshot.entrySet()) {
StatsInterface si = entry.getKey();
ArrayList list = new ArrayList(entry.getValue().size());
for (NativeFunction original : entry.getValue()) {
NativeFunction copy = original.copy();
copy.setCounter( si.functionCounter(copy.getOrdinal()) );
copy.subtract(original);
list.add(copy);
}
rc.put(si, list);
}
return new NativeStats(rc);
}
/**
* Dumps the stats to the print stream in a JSON format.
* @param ps
*/
public void dump(PrintStream ps) {
boolean firstSI=true;
for (Entry> entry : snapshot.entrySet()) {
StatsInterface si = entry.getKey();
ArrayList funcs = entry.getValue();
int total = 0;
for (NativeFunction func : funcs) {
total += func.getCounter();
}
if( !firstSI ) {
ps.print(", ");
}
firstSI=false;
ps.print("[");
if( total>0 ) {
ps.println("{ ");
ps.println(" \"class\": \""+si.getNativeClass()+"\",");
ps.println(" \"total\": "+total+", ");
ps.print(" \"functions\": {");
boolean firstFunc=true;
for (NativeFunction func : funcs) {
if (func.getCounter() > 0) {
if( !firstFunc ) {
ps.print(",");
}
firstFunc=false;
ps.println();
ps.print(" \""+func.getName()+"\": "+func.getCounter());
}
}
ps.println();
ps.println(" }");
ps.print("}");
}
ps.print("]");
}
}
static private HashMap> snapshot(Collection classes) {
HashMap> rc = new HashMap>();
for (StatsInterface sc : classes) {
int count = sc.functionCount();
ArrayList functions = new ArrayList(count);
for (int i = 0; i < count; i++) {
String name = (String) sc.functionName(i);
functions.add(new NativeFunction(i, name, 0));
}
Collections.sort(functions);
rc.put(sc, functions);
}
return rc;
}
}
hawtjni-1.0~+git0c502e20c4/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/T32.java 0000664 0000000 0000000 00000001421 11426650065 0032303 0 ustar 00root root 0000000 0000000 /*******************************************************************************
* Copyright (c) 2009 Progress Software, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.fusesource.hawtjni.runtime;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
@Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE})
@Retention(RetentionPolicy.RUNTIME)
public @interface T32 {
}
hawtjni-1.0~+git0c502e20c4/license.txt 0000664 0000000 0000000 00000057025 11426650065 0017404 0 ustar 00root root 0000000 0000000
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-----------------------------------------------------------------------------
Eclipse Public License - Version 1.0
Eclipse Public License - v 1.0
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
AGREEMENT.