src/macosx/native/jobjc/src/core/java/com/apple/jobjc/Coder.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -33,30 +33,30 @@
import com.apple.jobjc.PrimitiveCoder.FloatCoder;
import com.apple.jobjc.PrimitiveCoder.SCharCoder;
import com.apple.jobjc.PrimitiveCoder.SIntCoder;
import com.apple.jobjc.PrimitiveCoder.SLongLongCoder;
import com.apple.jobjc.PrimitiveCoder.SShortCoder;
-import javax.tools.annotation.GenerateNativeHeader;
+import java.lang.annotation.Native;
public abstract class Coder<T> {
private static native long getNativeFFITypePtrForCode(final int code);
- static final int FFI_VOID = 0;
- static final int FFI_PTR = FFI_VOID+1;
+ @Native static final int FFI_VOID = 0;
+ @Native static final int FFI_PTR = FFI_VOID+1;
- static final int FFI_SINT8 = FFI_PTR+1;
- static final int FFI_UINT8 = FFI_SINT8+1;
- static final int FFI_SINT16 = FFI_UINT8+1;
- static final int FFI_UINT16 = FFI_SINT16+1;
- static final int FFI_SINT32 = FFI_UINT16+1;
- static final int FFI_UINT32 = FFI_SINT32+1;
- static final int FFI_SINT64 = FFI_UINT32+1;
- static final int FFI_UINT64 = FFI_SINT64+1;
-
- static final int FFI_FLOAT = FFI_UINT64+1;
- static final int FFI_DOUBLE = FFI_FLOAT+1;
- static final int FFI_LONGDOUBLE = FFI_DOUBLE+1;
+ @Native static final int FFI_SINT8 = FFI_PTR+1;
+ @Native static final int FFI_UINT8 = FFI_SINT8+1;
+ @Native static final int FFI_SINT16 = FFI_UINT8+1;
+ @Native static final int FFI_UINT16 = FFI_SINT16+1;
+ @Native static final int FFI_SINT32 = FFI_UINT16+1;
+ @Native static final int FFI_UINT32 = FFI_SINT32+1;
+ @Native static final int FFI_SINT64 = FFI_UINT32+1;
+ @Native static final int FFI_UINT64 = FFI_SINT64+1;
+
+ @Native static final int FFI_FLOAT = FFI_UINT64+1;
+ @Native static final int FFI_DOUBLE = FFI_FLOAT+1;
+ @Native static final int FFI_LONGDOUBLE = FFI_DOUBLE+1;
private static long[] ffiCodesToFFITypePtrs;
static{
System.loadLibrary("JObjC");
ffiCodesToFFITypePtrs = new long[FFI_LONGDOUBLE + 1];
@@ -141,32 +141,26 @@
return getCoderAtRuntimeForType(inst.getClass());
}
//
- /* No native methods here, but the constants are needed in the supporting JNI code */
- @GenerateNativeHeader
public static final class VoidCoder extends Coder<Object>{
public static final VoidCoder INST = new VoidCoder();
public VoidCoder(){ super(FFI_VOID, "v", Void.class, void.class); }
@Override public int sizeof(Width w) { return -1; }
@Override public Object pop(JObjCRuntime runtime, long addr) { throw new RuntimeException("Trying to pop a Void."); }
@Override public void push(JObjCRuntime runtime, long addr, Object x) { throw new RuntimeException("Trying to push a Void."); }
}
- /* No native methods here, but the constants are needed in the supporting JNI code */
- @GenerateNativeHeader
public static final class UnknownCoder extends Coder<Object> {
public static final UnknownCoder INST = new UnknownCoder();
public UnknownCoder(){ super(-1, "?", null, null); }
@Override public int sizeof(Width w) { return -1; }
@Override public void push(JObjCRuntime runtime, long addr, Object x) { throw new RuntimeException("Coder not implemented");}
@Override public Object pop(JObjCRuntime runtime, long addr) { throw new RuntimeException("Coder not implemented"); }
}
- /* No native methods here, but the constants are needed in the supporting JNI code */
- @GenerateNativeHeader
public static final class PrimitivePointerCoder extends Coder<Long> {
public static final PrimitivePointerCoder INST = new PrimitivePointerCoder();
public PrimitivePointerCoder(){ super(Coder.FFI_PTR, "^?", Long.class, long.class); }
@Override public int sizeof(Width w) { return JObjCRuntime.PTR_LEN; }
@@ -192,12 +186,10 @@
@Override public Long pop(JObjCRuntime runtime, long addr) { return popPtr(runtime, addr); }
@Override public void push(JObjCRuntime runtime, long addr, Long x) { push(runtime, addr, (long) x); }
}
- /* No native methods here, but the constants are needed in the supporting JNI code */
- @GenerateNativeHeader
public static final class PointerCoder extends Coder<Pointer> {
public static final PointerCoder INST = new PointerCoder();
public PointerCoder(){ super(FFI_PTR, "^?", Pointer.class); }
@Override public int sizeof(Width w) { return PrimitivePointerCoder.INST.sizeof(w); }
@@ -207,12 +199,10 @@
@Override public void push(JObjCRuntime runtime, long addr, Pointer x) {
PrimitivePointerCoder.INST.push(runtime, addr, x == null ? 0 : x.ptr);
}
}
- /* No native methods here, but the constants are needed in the supporting JNI code */
- @GenerateNativeHeader
public static final class SELCoder extends Coder<SEL> {
public static final SELCoder INST = new SELCoder();
public SELCoder(){ super(FFI_PTR, ":", SEL.class); }
@Override public int sizeof(Width w) { return PrimitivePointerCoder.INST.sizeof(w); }
@@ -222,12 +212,10 @@
@Override public SEL pop(JObjCRuntime runtime, long addr) {
return new SEL(PrimitivePointerCoder.INST.popPtr(runtime, addr));
}
}
- /* No native methods here, but the constants are needed in the supporting JNI code */
- @GenerateNativeHeader
public static abstract class StructCoder extends Coder<Struct> {
private final FFIType ffiType;
final int sizeof;
public StructCoder(final int sizeof, final Coder... elementCoders){
@@ -265,12 +253,10 @@
runtime.unsafe.copyMemory(addr, s.raw.bufferPtr, sizeof);
return s;
}
}
- /* No native methods here, but the constants are needed in the supporting JNI code */
- @GenerateNativeHeader
public static final class IDCoder extends Coder<ID>{
public static final IDCoder INST = new IDCoder();
public IDCoder(){ super(FFI_PTR, "@", ID.class); }
@Override public int sizeof(Width w) { return PrimitivePointerCoder.INST.sizeof(w); }
@@ -285,12 +271,10 @@
@Override public void push(final JObjCRuntime runtime, final long addr, final ID x) {
PointerCoder.INST.push(runtime, addr, x);
}
}
- /* No native methods here, but the constants are needed in the supporting JNI code */
- @GenerateNativeHeader
public static final class NSClassCoder extends Coder<NSClass>{
public static final NSClassCoder INST = new NSClassCoder();
public NSClassCoder(){ super(FFI_PTR, "#", NSClass.class); }
@Override public int sizeof(Width w) { return PrimitivePointerCoder.INST.sizeof(w); }