Skip to content

Commit

Permalink
[GR-9387] AssertionError in ContextProfile with multiple null contexts.
Browse files Browse the repository at this point in the history
PullRequest: graal/1340
  • Loading branch information
woess committed Apr 17, 2018
2 parents 6a5f9e6 + e9d4aa3 commit 595a0c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,23 @@ protected void disposeContext(LanguageContext context) {
c.close();
}

@Test
public void testNullContext() {
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected LanguageContext createContext(TruffleLanguage.Env env) {
return null;
}
});
try (Engine engine = Engine.create()) {
for (int i = 0; i < 2; i++) {
try (Context context = Context.newBuilder(ProxyLanguage.ID).engine(engine).build()) {
context.initialize(ProxyLanguage.ID);
}
}
}
}

@Test
public void testExceptionGetSourceLocation() {
try (Context context = Context.create(LanguageSPITestLanguage.ID)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ void ensureInitialized() {
ContextProfile requireProfile() {
if (profile == null) {
CompilerDirectives.transferToInterpreter();
throw new AssertionError(
"No language context is active on this thread.");
throw new AssertionError("No language context is active on this thread.");
}
return profile;
}
Expand Down Expand Up @@ -245,16 +244,15 @@ private Object lookupLanguageContext(PolyglotContextImpl context) {
Env env = context.contexts[language.index].env;
if (env == null) {
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException(
"The language context is not yet initialized or already disposed. ");
throw new IllegalStateException("The language context is not yet initialized or already disposed.");
}
return LANGUAGE.getContext(env);
}

void notifyContextCreate(Env env) {
if (singleContext.isValid()) {
Object cachedSingle = this.cachedSingleContext;
assert cachedSingle != LANGUAGE.getContext(env);
assert cachedSingle != LANGUAGE.getContext(env) || cachedSingle == null : "Non-null context objects should be distinct";
if (cachedSingle == UNSET_CONTEXT) {
if (singleContext.isValid()) {
cachedSingleContext = LANGUAGE.getContext(env);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.net.URI;
import java.nio.file.FileSystemNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
Expand All @@ -44,6 +46,7 @@
import org.graalvm.options.OptionValues;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.io.FileSystem;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
Expand All @@ -62,9 +65,6 @@
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import java.net.URI;
import java.nio.file.FileSystemNotFoundException;
import org.graalvm.polyglot.io.FileSystem;

/**
* A Truffle language implementation contains all the services a language should provide to make it
Expand All @@ -90,7 +90,7 @@
* that is created using the {@linkplain org.graalvm.polyglot.Engine.Builder#build() engine builder}
* . If a {@linkplain org.graalvm.polyglot.Context context} is created without a
* {@linkplain org.graalvm.polyglot.Engine engine} then the language implementation instance is
* created for each context implicitely.
* created for each context implicitly.
* <p>
* Global state can be shared between multiple language context instances by saving them as in a
* field of the {@link TruffleLanguage} subclass. The implementation needs to ensure data isolation
Expand Down Expand Up @@ -317,12 +317,15 @@ protected TruffleLanguage() {
* {@link Env#parse(com.oracle.truffle.api.source.Source, java.lang.String...) calls into other
* languages} and assuming your language is already initialized and others can see it would be
* wrong - until you return from this method, the initialization isn't over. The same is true
* for instrumentation, the instruments can not receive any meta data about code executed during
* for instrumentation, the instruments cannot receive any meta data about code executed during
* context creation. Should there be a need to perform complex initialization, do it by
* overriding the {@link #initializeContext(java.lang.Object)} method.
* <p>
* May return {@code null} if the language does not need any per-{@linkplain Context context}
* state. Otherwise it should return a new object instance every time it is called.
*
* @param env the environment the language is supposed to operate in
* @return internal data of the language in given environment
* @return internal data of the language in given environment or {@code null}
* @since 0.8 or earlier
*/
protected abstract C createContext(Env env);
Expand Down Expand Up @@ -1307,7 +1310,7 @@ public Object getPolyglotBindings() {
}

/**
* Explicitely imports a symbol from the polyglot bindings. The behavior of this method is
* Explicitly imports a symbol from the polyglot bindings. The behavior of this method is
* equivalent to sending a READ message to the {@link #getPolyglotBindings() polyglot
* bindings} object. Reading a symbol that does not exist will return <code>null</code>.
* <p>
Expand All @@ -1327,7 +1330,7 @@ public Object importSymbol(String symbolName) {
}

/**
* Explicitely exports a symbol to the polyglot bindings object. The behavior of this method
* Explicitly exports a symbol to the polyglot bindings object. The behavior of this method
* is equivalent to sending a WRITE message to the {@link #getPolyglotBindings() polyglot
* bindings} object. Exporting a symbol with a <code>null</code> value will remove the
* symbol from the polyglot object.
Expand Down

0 comments on commit 595a0c6

Please sign in to comment.