Skip to content

Commit

Permalink
Fix merge problem with recent NFI refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
rschatz committed Jan 30, 2018
1 parent 4a811e1 commit 4907f1a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2018, 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
Expand Down Expand Up @@ -70,7 +70,7 @@ private NativeClosure(CallTarget callTarget, Target_com_oracle_truffle_nfi_impl_

int skipped = 0;
for (Object type : signature.getArgTypes()) {
if (Target_com_oracle_truffle_nfi_LibFFIType_EnvType.class.isInstance(type)) {
if (Target_com_oracle_truffle_nfi_impl_LibFFIType_EnvType.class.isInstance(type)) {
skipped++;
}
}
Expand Down Expand Up @@ -113,13 +113,13 @@ private Object call(WordPointer argPointers, ByteBuffer retBuffer) {
Object[] args = new Object[length];
for (int i = 0; i < argTypes.length; i++) {
Object type = argTypes[i];
if (Target_com_oracle_truffle_nfi_LibFFIType_StringType.class.isInstance(type)) {
if (Target_com_oracle_truffle_nfi_impl_LibFFIType_StringType.class.isInstance(type)) {
CCharPointerPointer argPtr = argPointers.read(i);
args[argIdx++] = TruffleNFISupport.utf8ToJavaString(argPtr.read());
} else if (Target_com_oracle_truffle_nfi_LibFFIType_ObjectType.class.isInstance(type)) {
} else if (Target_com_oracle_truffle_nfi_impl_LibFFIType_ObjectType.class.isInstance(type)) {
WordPointer argPtr = argPointers.read(i);
args[argIdx++] = ImageSingletons.lookup(TruffleNFISupport.class).resolveHandle(argPtr.read());
} else if (Target_com_oracle_truffle_nfi_LibFFIType_EnvType.class.isInstance(type)) {
} else if (Target_com_oracle_truffle_nfi_impl_LibFFIType_EnvType.class.isInstance(type)) {
// skip
} else {
WordPointer argPtr = argPointers.read(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2018, 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
Expand Down Expand Up @@ -36,13 +36,13 @@ final class Target_com_oracle_truffle_nfi_impl_LibFFIType {
}

@TargetClass(className = "com.oracle.truffle.nfi.impl.LibFFIType", innerClass = "StringType", onlyWith = TruffleNFIFeature.IsEnabled.class)
final class Target_com_oracle_truffle_nfi_LibFFIType_StringType {
final class Target_com_oracle_truffle_nfi_impl_LibFFIType_StringType {
}

@TargetClass(className = "com.oracle.truffle.nfi.impl.LibFFIType", innerClass = "ObjectType", onlyWith = TruffleNFIFeature.IsEnabled.class)
final class Target_com_oracle_truffle_nfi_LibFFIType_ObjectType {
final class Target_com_oracle_truffle_nfi_impl_LibFFIType_ObjectType {
}

@TargetClass(className = "com.oracle.truffle.nfi.impl.LibFFIType", innerClass = "EnvType", onlyWith = TruffleNFIFeature.IsEnabled.class)
final class Target_com_oracle_truffle_nfi_LibFFIType_EnvType {
final class Target_com_oracle_truffle_nfi_impl_LibFFIType_EnvType {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2018, 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
Expand Down Expand Up @@ -27,20 +27,35 @@
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.TruffleLanguage.Env;
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.nfi.NFILanguage.Context;
import com.oracle.truffle.nfi.types.NativeSource;
import com.oracle.truffle.nfi.types.Parser;

@TruffleLanguage.Registration(id = "nfi", name = "TruffleNFI", version = "0.1", mimeType = NFILanguage.MIME_TYPE, internal = true)
public class NFILanguage extends TruffleLanguage<Env> {
public class NFILanguage extends TruffleLanguage<Context> {

public static final String MIME_TYPE = "application/x-native";

static class Context {

Env env;

Context(Env env) {
this.env = env;
}
}

@Override
protected Env createContext(Env env) {
return env;
protected Context createContext(Env env) {
return new Context(env);
}

@Override
protected boolean patchContext(Context context, Env newEnv) {
context.env = newEnv;
return true;
}

@Override
Expand All @@ -56,14 +71,14 @@ protected CallTarget parse(ParsingRequest request) throws Exception {
}

Source backendSource = Source.newBuilder(source.getLibraryDescriptor()).mimeType("trufflenfi/" + backendId).name("<nfi-impl>").build();
CallTarget backendTarget = getContextReference().get().parse(backendSource);
CallTarget backendTarget = getContextReference().get().env.parse(backendSource);
DirectCallNode loadLibrary = DirectCallNode.create(backendTarget);

return Truffle.getRuntime().createCallTarget(new NFIRootNode(this, loadLibrary, source));
}

@Override
protected Object getLanguageGlobal(Env context) {
protected Object getLanguageGlobal(Context context) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2018, 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
Expand Down Expand Up @@ -43,7 +43,7 @@

class NFIContext {

final Env env;
Env env;

private long nativeContext;
private final ThreadLocal<NativeEnv> nativeEnv = ThreadLocal.withInitial(new NativeEnvSupplier());
Expand Down Expand Up @@ -84,6 +84,10 @@ public NativeEnv get() {
this.env = env;
}

void patchEnv(Env newEnv) {
this.env = newEnv;
}

// called from native
long getNativeEnv() {
return nativeEnv.get().pointer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2018, 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
Expand Down Expand Up @@ -51,6 +51,7 @@ protected void initializeContext(NFIContext context) throws Exception {

@Override
protected boolean patchContext(NFIContext context, Env newEnv) {
context.patchEnv(newEnv);
context.initialize();
return true;
}
Expand Down

0 comments on commit 4907f1a

Please sign in to comment.