com.apple.jobjc.Coder.PrimitivePointerCoder Java Examples

The following examples show how to use com.apple.jobjc.Coder.PrimitivePointerCoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NativeArgumentBuffer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override public String toString() {
    final StringBuilder builder = new StringBuilder();
    final long bptr = buffer.bufferPtr;

    for(long i = bptr; i < bptr + ARG_VALS_OFFSET; i += JObjCRuntime.PTR_LEN){
        if(argPtrsPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    builder.append("\n");

    for(long i = bptr + ARG_VALS_OFFSET; i < bptr + BUF_SIZE; i += JObjCRuntime.PTR_LEN){
        if(argValuesPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    return builder.toString();
}
 
Example #2
Source File: NativeArgumentBuffer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override public String toString() {
    final StringBuilder builder = new StringBuilder();
    final long bptr = buffer.bufferPtr;

    for(long i = bptr; i < bptr + ARG_VALS_OFFSET; i += JObjCRuntime.PTR_LEN){
        if(argPtrsPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    builder.append("\n");

    for(long i = bptr + ARG_VALS_OFFSET; i < bptr + BUF_SIZE; i += JObjCRuntime.PTR_LEN){
        if(argValuesPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    return builder.toString();
}
 
Example #3
Source File: CIF.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static CIF createCIFFor(final NativeArgumentBuffer args, final Coder returnCoder, final Coder ... argCoders) {
    NativeBuffer cifBuf = new NativeBuffer(SIZEOF + (argCoders.length * JObjCRuntime.PTR_LEN));
    final long argsPtr = cifBuf.bufferPtr + SIZEOF;

    {
        long argsIterPtr = argsPtr;
        for(final Coder coder : argCoders){
            PrimitivePointerCoder.INST.push(args.runtime, argsIterPtr, coder.getFFITypePtr());
            argsIterPtr += JObjCRuntime.PTR_LEN;
        }
    }

    boolean ok = prepCIF(cifBuf.bufferPtr, argCoders.length, returnCoder.getFFITypePtr(), argsPtr);
    if(!ok)
        throw new RuntimeException("ffi_prep_cif failed.");

    return new CIF(cifBuf, returnCoder, argCoders);
}
 
Example #4
Source File: NativeArgumentBuffer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override public String toString() {
    final StringBuilder builder = new StringBuilder();
    final long bptr = buffer.bufferPtr;

    for(long i = bptr; i < bptr + ARG_VALS_OFFSET; i += JObjCRuntime.PTR_LEN){
        if(argPtrsPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    builder.append("\n");

    for(long i = bptr + ARG_VALS_OFFSET; i < bptr + BUF_SIZE; i += JObjCRuntime.PTR_LEN){
        if(argValuesPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    return builder.toString();
}
 
Example #5
Source File: Invoke.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void init(final NativeArgumentBuffer argBuf, final ID obj, final NSClass cls) {
    funCall.init(argBuf);

    // Instead of mallocing a struct, or keeping another thread local,
    // let's write objc_super out to the argbuf, and then point an argument
    // to the data.

    final long valPtr = argBuf.argValuesPtr;
    final int ptrLen = JObjCRuntime.PTR_LEN;

    IDCoder     .INST.push(argBuf.runtime, valPtr,          obj);
    NSClassCoder.INST.push(argBuf.runtime, valPtr + ptrLen, cls);
    argBuf.argValuesPtr += ptrLen + ptrLen;

    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, valPtr);
    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, selPtr);
}
 
Example #6
Source File: FunctionTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void testInvokeOneParam() throws Throwable {
    final FunCall getHomeDirFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getAppKit(), "NSHomeDirectory", PointerCoder.INST);

    getHomeDirFxn.init(nativeBuffer);
    getHomeDirFxn.invoke(nativeBuffer);

    final long homeDirPtr = PrimitivePointerCoder.INST.pop(nativeBuffer);
    System.out.println("0x" + Long.toHexString(homeDirPtr) + ": " + UnsafeRuntimeAccess.getDescriptionForPtr(homeDirPtr));

    final FunCall getTypeOfFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getFoundation(), "NSLog", PointerCoder.INST, PointerCoder.INST);
    getTypeOfFxn.init(nativeBuffer);
    PrimitivePointerCoder.INST.push(runtime, nativeBuffer, homeDirPtr);
    getTypeOfFxn.invoke(nativeBuffer);

//    long typePtr = PointerCoder.pointer_coder.popPtr(nativeBuffer);
//    System.out.println("0x" + Long.toHexString(typePtr) + ": " + TestUtils.getDescriptionForPtr(typePtr));
}
 
Example #7
Source File: FunctionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void testInvokeOneParam() throws Throwable {
    final FunCall getHomeDirFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getAppKit(), "NSHomeDirectory", PointerCoder.INST);

    getHomeDirFxn.init(nativeBuffer);
    getHomeDirFxn.invoke(nativeBuffer);

    final long homeDirPtr = PrimitivePointerCoder.INST.pop(nativeBuffer);
    System.out.println("0x" + Long.toHexString(homeDirPtr) + ": " + UnsafeRuntimeAccess.getDescriptionForPtr(homeDirPtr));

    final FunCall getTypeOfFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getFoundation(), "NSLog", PointerCoder.INST, PointerCoder.INST);
    getTypeOfFxn.init(nativeBuffer);
    PrimitivePointerCoder.INST.push(runtime, nativeBuffer, homeDirPtr);
    getTypeOfFxn.invoke(nativeBuffer);

//    long typePtr = PointerCoder.pointer_coder.popPtr(nativeBuffer);
//    System.out.println("0x" + Long.toHexString(typePtr) + ": " + TestUtils.getDescriptionForPtr(typePtr));
}
 
Example #8
Source File: Invoke.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void init(final NativeArgumentBuffer argBuf, final ID obj, final NSClass cls) {
    funCall.init(argBuf);

    // Instead of mallocing a struct, or keeping another thread local,
    // let's write objc_super out to the argbuf, and then point an argument
    // to the data.

    final long valPtr = argBuf.argValuesPtr;
    final int ptrLen = JObjCRuntime.PTR_LEN;

    IDCoder     .INST.push(argBuf.runtime, valPtr,          obj);
    NSClassCoder.INST.push(argBuf.runtime, valPtr + ptrLen, cls);
    argBuf.argValuesPtr += ptrLen + ptrLen;

    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, valPtr);
    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, selPtr);
}
 
Example #9
Source File: CIF.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static CIF createCIFFor(final NativeArgumentBuffer args, final Coder returnCoder, final Coder ... argCoders) {
    NativeBuffer cifBuf = new NativeBuffer(SIZEOF + (argCoders.length * JObjCRuntime.PTR_LEN));
    final long argsPtr = cifBuf.bufferPtr + SIZEOF;

    {
        long argsIterPtr = argsPtr;
        for(final Coder coder : argCoders){
            PrimitivePointerCoder.INST.push(args.runtime, argsIterPtr, coder.getFFITypePtr());
            argsIterPtr += JObjCRuntime.PTR_LEN;
        }
    }

    boolean ok = prepCIF(cifBuf.bufferPtr, argCoders.length, returnCoder.getFFITypePtr(), argsPtr);
    if(!ok)
        throw new RuntimeException("ffi_prep_cif failed.");

    return new CIF(cifBuf, returnCoder, argCoders);
}
 
Example #10
Source File: FunctionTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testInvokeOneParam() throws Throwable {
    final FunCall getHomeDirFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getAppKit(), "NSHomeDirectory", PointerCoder.INST);

    getHomeDirFxn.init(nativeBuffer);
    getHomeDirFxn.invoke(nativeBuffer);

    final long homeDirPtr = PrimitivePointerCoder.INST.pop(nativeBuffer);
    System.out.println("0x" + Long.toHexString(homeDirPtr) + ": " + UnsafeRuntimeAccess.getDescriptionForPtr(homeDirPtr));

    final FunCall getTypeOfFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getFoundation(), "NSLog", PointerCoder.INST, PointerCoder.INST);
    getTypeOfFxn.init(nativeBuffer);
    PrimitivePointerCoder.INST.push(runtime, nativeBuffer, homeDirPtr);
    getTypeOfFxn.invoke(nativeBuffer);

//    long typePtr = PointerCoder.pointer_coder.popPtr(nativeBuffer);
//    System.out.println("0x" + Long.toHexString(typePtr) + ": " + TestUtils.getDescriptionForPtr(typePtr));
}
 
Example #11
Source File: Invoke.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void init(final NativeArgumentBuffer argBuf, final ID obj, final NSClass cls) {
    funCall.init(argBuf);

    // Instead of mallocing a struct, or keeping another thread local,
    // let's write objc_super out to the argbuf, and then point an argument
    // to the data.

    final long valPtr = argBuf.argValuesPtr;
    final int ptrLen = JObjCRuntime.PTR_LEN;

    IDCoder     .INST.push(argBuf.runtime, valPtr,          obj);
    NSClassCoder.INST.push(argBuf.runtime, valPtr + ptrLen, cls);
    argBuf.argValuesPtr += ptrLen + ptrLen;

    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, valPtr);
    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, selPtr);
}
 
Example #12
Source File: NativeArgumentBuffer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override public String toString() {
    final StringBuilder builder = new StringBuilder();
    final long bptr = buffer.bufferPtr;

    for(long i = bptr; i < bptr + ARG_VALS_OFFSET; i += JObjCRuntime.PTR_LEN){
        if(argPtrsPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    builder.append("\n");

    for(long i = bptr + ARG_VALS_OFFSET; i < bptr + BUF_SIZE; i += JObjCRuntime.PTR_LEN){
        if(argValuesPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    return builder.toString();
}
 
Example #13
Source File: CIF.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static CIF createCIFFor(final NativeArgumentBuffer args, final Coder returnCoder, final Coder ... argCoders) {
    NativeBuffer cifBuf = new NativeBuffer(SIZEOF + (argCoders.length * JObjCRuntime.PTR_LEN));
    final long argsPtr = cifBuf.bufferPtr + SIZEOF;

    {
        long argsIterPtr = argsPtr;
        for(final Coder coder : argCoders){
            PrimitivePointerCoder.INST.push(args.runtime, argsIterPtr, coder.getFFITypePtr());
            argsIterPtr += JObjCRuntime.PTR_LEN;
        }
    }

    boolean ok = prepCIF(cifBuf.bufferPtr, argCoders.length, returnCoder.getFFITypePtr(), argsPtr);
    if(!ok)
        throw new RuntimeException("ffi_prep_cif failed.");

    return new CIF(cifBuf, returnCoder, argCoders);
}
 
Example #14
Source File: FunctionTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testInvokeOneParam() throws Throwable {
    final FunCall getHomeDirFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getAppKit(), "NSHomeDirectory", PointerCoder.INST);

    getHomeDirFxn.init(nativeBuffer);
    getHomeDirFxn.invoke(nativeBuffer);

    final long homeDirPtr = PrimitivePointerCoder.INST.pop(nativeBuffer);
    System.out.println("0x" + Long.toHexString(homeDirPtr) + ": " + UnsafeRuntimeAccess.getDescriptionForPtr(homeDirPtr));

    final FunCall getTypeOfFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getFoundation(), "NSLog", PointerCoder.INST, PointerCoder.INST);
    getTypeOfFxn.init(nativeBuffer);
    PrimitivePointerCoder.INST.push(runtime, nativeBuffer, homeDirPtr);
    getTypeOfFxn.invoke(nativeBuffer);

//    long typePtr = PointerCoder.pointer_coder.popPtr(nativeBuffer);
//    System.out.println("0x" + Long.toHexString(typePtr) + ": " + TestUtils.getDescriptionForPtr(typePtr));
}
 
Example #15
Source File: Invoke.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void init(final NativeArgumentBuffer argBuf, final ID obj, final NSClass cls) {
    funCall.init(argBuf);

    // Instead of mallocing a struct, or keeping another thread local,
    // let's write objc_super out to the argbuf, and then point an argument
    // to the data.

    final long valPtr = argBuf.argValuesPtr;
    final int ptrLen = JObjCRuntime.PTR_LEN;

    IDCoder     .INST.push(argBuf.runtime, valPtr,          obj);
    NSClassCoder.INST.push(argBuf.runtime, valPtr + ptrLen, cls);
    argBuf.argValuesPtr += ptrLen + ptrLen;

    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, valPtr);
    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, selPtr);
}
 
Example #16
Source File: FunctionTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testInvokeOneParam() throws Throwable {
    final FunCall getHomeDirFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getAppKit(), "NSHomeDirectory", PointerCoder.INST);

    getHomeDirFxn.init(nativeBuffer);
    getHomeDirFxn.invoke(nativeBuffer);

    final long homeDirPtr = PrimitivePointerCoder.INST.pop(nativeBuffer);
    System.out.println("0x" + Long.toHexString(homeDirPtr) + ": " + UnsafeRuntimeAccess.getDescriptionForPtr(homeDirPtr));

    final FunCall getTypeOfFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getFoundation(), "NSLog", PointerCoder.INST, PointerCoder.INST);
    getTypeOfFxn.init(nativeBuffer);
    PrimitivePointerCoder.INST.push(runtime, nativeBuffer, homeDirPtr);
    getTypeOfFxn.invoke(nativeBuffer);

//    long typePtr = PointerCoder.pointer_coder.popPtr(nativeBuffer);
//    System.out.println("0x" + Long.toHexString(typePtr) + ": " + TestUtils.getDescriptionForPtr(typePtr));
}
 
Example #17
Source File: CIF.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static CIF createCIFFor(final NativeArgumentBuffer args, final Coder returnCoder, final Coder ... argCoders) {
    NativeBuffer cifBuf = new NativeBuffer(SIZEOF + (argCoders.length * JObjCRuntime.PTR_LEN));
    final long argsPtr = cifBuf.bufferPtr + SIZEOF;

    {
        long argsIterPtr = argsPtr;
        for(final Coder coder : argCoders){
            PrimitivePointerCoder.INST.push(args.runtime, argsIterPtr, coder.getFFITypePtr());
            argsIterPtr += JObjCRuntime.PTR_LEN;
        }
    }

    boolean ok = prepCIF(cifBuf.bufferPtr, argCoders.length, returnCoder.getFFITypePtr(), argsPtr);
    if(!ok)
        throw new RuntimeException("ffi_prep_cif failed.");

    return new CIF(cifBuf, returnCoder, argCoders);
}
 
Example #18
Source File: Invoke.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void init(final NativeArgumentBuffer argBuf, final ID obj, final NSClass cls) {
    funCall.init(argBuf);

    // Instead of mallocing a struct, or keeping another thread local,
    // let's write objc_super out to the argbuf, and then point an argument
    // to the data.

    final long valPtr = argBuf.argValuesPtr;
    final int ptrLen = JObjCRuntime.PTR_LEN;

    IDCoder     .INST.push(argBuf.runtime, valPtr,          obj);
    NSClassCoder.INST.push(argBuf.runtime, valPtr + ptrLen, cls);
    argBuf.argValuesPtr += ptrLen + ptrLen;

    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, valPtr);
    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, selPtr);
}
 
Example #19
Source File: FunctionTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void testInvokeOneParam() throws Throwable {
    final FunCall getHomeDirFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getAppKit(), "NSHomeDirectory", PointerCoder.INST);

    getHomeDirFxn.init(nativeBuffer);
    getHomeDirFxn.invoke(nativeBuffer);

    final long homeDirPtr = PrimitivePointerCoder.INST.pop(nativeBuffer);
    System.out.println("0x" + Long.toHexString(homeDirPtr) + ": " + UnsafeRuntimeAccess.getDescriptionForPtr(homeDirPtr));

    final FunCall getTypeOfFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getFoundation(), "NSLog", PointerCoder.INST, PointerCoder.INST);
    getTypeOfFxn.init(nativeBuffer);
    PrimitivePointerCoder.INST.push(runtime, nativeBuffer, homeDirPtr);
    getTypeOfFxn.invoke(nativeBuffer);

//    long typePtr = PointerCoder.pointer_coder.popPtr(nativeBuffer);
//    System.out.println("0x" + Long.toHexString(typePtr) + ": " + TestUtils.getDescriptionForPtr(typePtr));
}
 
Example #20
Source File: Invoke.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void init(final NativeArgumentBuffer argBuf, final ID obj, final NSClass cls) {
    funCall.init(argBuf);

    // Instead of mallocing a struct, or keeping another thread local,
    // let's write objc_super out to the argbuf, and then point an argument
    // to the data.

    final long valPtr = argBuf.argValuesPtr;
    final int ptrLen = JObjCRuntime.PTR_LEN;

    IDCoder     .INST.push(argBuf.runtime, valPtr,          obj);
    NSClassCoder.INST.push(argBuf.runtime, valPtr + ptrLen, cls);
    argBuf.argValuesPtr += ptrLen + ptrLen;

    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, valPtr);
    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, selPtr);
}
 
Example #21
Source File: CIF.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static CIF createCIFFor(final NativeArgumentBuffer args, final Coder returnCoder, final Coder ... argCoders) {
    NativeBuffer cifBuf = new NativeBuffer(SIZEOF + (argCoders.length * JObjCRuntime.PTR_LEN));
    final long argsPtr = cifBuf.bufferPtr + SIZEOF;

    {
        long argsIterPtr = argsPtr;
        for(final Coder coder : argCoders){
            PrimitivePointerCoder.INST.push(args.runtime, argsIterPtr, coder.getFFITypePtr());
            argsIterPtr += JObjCRuntime.PTR_LEN;
        }
    }

    boolean ok = prepCIF(cifBuf.bufferPtr, argCoders.length, returnCoder.getFFITypePtr(), argsPtr);
    if(!ok)
        throw new RuntimeException("ffi_prep_cif failed.");

    return new CIF(cifBuf, returnCoder, argCoders);
}
 
Example #22
Source File: CIF.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static CIF createCIFFor(final NativeArgumentBuffer args, final Coder returnCoder, final Coder ... argCoders) {
    NativeBuffer cifBuf = new NativeBuffer(SIZEOF + (argCoders.length * JObjCRuntime.PTR_LEN));
    final long argsPtr = cifBuf.bufferPtr + SIZEOF;

    {
        long argsIterPtr = argsPtr;
        for(final Coder coder : argCoders){
            PrimitivePointerCoder.INST.push(args.runtime, argsIterPtr, coder.getFFITypePtr());
            argsIterPtr += JObjCRuntime.PTR_LEN;
        }
    }

    boolean ok = prepCIF(cifBuf.bufferPtr, argCoders.length, returnCoder.getFFITypePtr(), argsPtr);
    if(!ok)
        throw new RuntimeException("ffi_prep_cif failed.");

    return new CIF(cifBuf, returnCoder, argCoders);
}
 
Example #23
Source File: Invoke.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void init(final NativeArgumentBuffer argBuf, final ID obj, final NSClass cls) {
    funCall.init(argBuf);

    // Instead of mallocing a struct, or keeping another thread local,
    // let's write objc_super out to the argbuf, and then point an argument
    // to the data.

    final long valPtr = argBuf.argValuesPtr;
    final int ptrLen = JObjCRuntime.PTR_LEN;

    IDCoder     .INST.push(argBuf.runtime, valPtr,          obj);
    NSClassCoder.INST.push(argBuf.runtime, valPtr + ptrLen, cls);
    argBuf.argValuesPtr += ptrLen + ptrLen;

    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, valPtr);
    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, selPtr);
}
 
Example #24
Source File: Invoke.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void init(final NativeArgumentBuffer argBuf, final ID obj, final NSClass cls) {
    funCall.init(argBuf);

    // Instead of mallocing a struct, or keeping another thread local,
    // let's write objc_super out to the argbuf, and then point an argument
    // to the data.

    final long valPtr = argBuf.argValuesPtr;
    final int ptrLen = JObjCRuntime.PTR_LEN;

    IDCoder     .INST.push(argBuf.runtime, valPtr,          obj);
    NSClassCoder.INST.push(argBuf.runtime, valPtr + ptrLen, cls);
    argBuf.argValuesPtr += ptrLen + ptrLen;

    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, valPtr);
    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, selPtr);
}
 
Example #25
Source File: NativeArgumentBuffer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override public String toString() {
    final StringBuilder builder = new StringBuilder();
    final long bptr = buffer.bufferPtr;

    for(long i = bptr; i < bptr + ARG_VALS_OFFSET; i += JObjCRuntime.PTR_LEN){
        if(argPtrsPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    builder.append("\n");

    for(long i = bptr + ARG_VALS_OFFSET; i < bptr + BUF_SIZE; i += JObjCRuntime.PTR_LEN){
        if(argValuesPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    return builder.toString();
}
 
Example #26
Source File: CIF.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static CIF createCIFFor(final NativeArgumentBuffer args, final Coder returnCoder, final Coder ... argCoders) {
    NativeBuffer cifBuf = new NativeBuffer(SIZEOF + (argCoders.length * JObjCRuntime.PTR_LEN));
    final long argsPtr = cifBuf.bufferPtr + SIZEOF;

    {
        long argsIterPtr = argsPtr;
        for(final Coder coder : argCoders){
            PrimitivePointerCoder.INST.push(args.runtime, argsIterPtr, coder.getFFITypePtr());
            argsIterPtr += JObjCRuntime.PTR_LEN;
        }
    }

    boolean ok = prepCIF(cifBuf.bufferPtr, argCoders.length, returnCoder.getFFITypePtr(), argsPtr);
    if(!ok)
        throw new RuntimeException("ffi_prep_cif failed.");

    return new CIF(cifBuf, returnCoder, argCoders);
}
 
Example #27
Source File: FunctionTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void testInvokeOneParam() throws Throwable {
    final FunCall getHomeDirFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getAppKit(), "NSHomeDirectory", PointerCoder.INST);

    getHomeDirFxn.init(nativeBuffer);
    getHomeDirFxn.invoke(nativeBuffer);

    final long homeDirPtr = PrimitivePointerCoder.INST.pop(nativeBuffer);
    System.out.println("0x" + Long.toHexString(homeDirPtr) + ": " + UnsafeRuntimeAccess.getDescriptionForPtr(homeDirPtr));

    final FunCall getTypeOfFxn = UnsafeRuntimeAccess.createFunCall(TestUtils.getFoundation(), "NSLog", PointerCoder.INST, PointerCoder.INST);
    getTypeOfFxn.init(nativeBuffer);
    PrimitivePointerCoder.INST.push(runtime, nativeBuffer, homeDirPtr);
    getTypeOfFxn.invoke(nativeBuffer);

//    long typePtr = PointerCoder.pointer_coder.popPtr(nativeBuffer);
//    System.out.println("0x" + Long.toHexString(typePtr) + ": " + TestUtils.getDescriptionForPtr(typePtr));
}
 
Example #28
Source File: Invoke.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void init(final NativeArgumentBuffer argBuf, final ID obj, final NSClass cls) {
    funCall.init(argBuf);

    // Instead of mallocing a struct, or keeping another thread local,
    // let's write objc_super out to the argbuf, and then point an argument
    // to the data.

    final long valPtr = argBuf.argValuesPtr;
    final int ptrLen = JObjCRuntime.PTR_LEN;

    IDCoder     .INST.push(argBuf.runtime, valPtr,          obj);
    NSClassCoder.INST.push(argBuf.runtime, valPtr + ptrLen, cls);
    argBuf.argValuesPtr += ptrLen + ptrLen;

    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, valPtr);
    PrimitivePointerCoder.INST.push(argBuf.runtime, argBuf, selPtr);
}
 
Example #29
Source File: NativeArgumentBuffer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override public String toString() {
    final StringBuilder builder = new StringBuilder();
    final long bptr = buffer.bufferPtr;

    for(long i = bptr; i < bptr + ARG_VALS_OFFSET; i += JObjCRuntime.PTR_LEN){
        if(argPtrsPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    builder.append("\n");

    for(long i = bptr + ARG_VALS_OFFSET; i < bptr + BUF_SIZE; i += JObjCRuntime.PTR_LEN){
        if(argValuesPtr == i)
            builder.append("*");
        builder.append(PrimitivePointerCoder.INST.popPtr(JObjCRuntime.inst(), i));
        builder.append(" ");
    }

    return builder.toString();
}
 
Example #30
Source File: CIF.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static CIF createCIFFor(final NativeArgumentBuffer args, final Coder returnCoder, final Coder ... argCoders) {
    NativeBuffer cifBuf = new NativeBuffer(SIZEOF + (argCoders.length * JObjCRuntime.PTR_LEN));
    final long argsPtr = cifBuf.bufferPtr + SIZEOF;

    {
        long argsIterPtr = argsPtr;
        for(final Coder coder : argCoders){
            PrimitivePointerCoder.INST.push(args.runtime, argsIterPtr, coder.getFFITypePtr());
            argsIterPtr += JObjCRuntime.PTR_LEN;
        }
    }

    boolean ok = prepCIF(cifBuf.bufferPtr, argCoders.length, returnCoder.getFFITypePtr(), argsPtr);
    if(!ok)
        throw new RuntimeException("ffi_prep_cif failed.");

    return new CIF(cifBuf, returnCoder, argCoders);
}