# HG changeset patch # User Michael Van De Vanter # Date 1442353764 25200 # Node ID 7c8c03389f0f5d4a40606d7f50ac6541e2f4b29c # Parent daaebd13b27a451d7643edb0abdc1772cb72da87 Truffle/Instrumentation: fix bug in registration of ASTProbers diff -r daaebd13b27a -r 7c8c03389f0f truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java --- a/truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java Tue Sep 15 12:10:50 2015 -0700 +++ b/truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java Tue Sep 15 14:49:24 2015 -0700 @@ -806,7 +806,9 @@ impl = LanguageCache.find(n, loader()); Instrumenter inst = TruffleVM.this.instrumenter; final ASTProber prober = SPI.getDefaultASTProber(TruffleVM.this, impl.getClass()); - inst.registerASTProber(prober); + if (prober != null) { + inst.registerASTProber(prober); + } env = SPI.attachEnv(TruffleVM.this, impl, out, err, in); } catch (Exception ex) { throw new IllegalStateException("Cannot initialize " + getShortName() + " language with implementation " + n, ex); diff -r daaebd13b27a -r 7c8c03389f0f truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java Tue Sep 15 12:10:50 2015 -0700 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java Tue Sep 15 14:49:24 2015 -0700 @@ -28,7 +28,10 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.TruffleLanguage; @@ -65,7 +68,7 @@ return visitor.source; } - private final List astProbers = new ArrayList<>(); + private final Set astProbers = Collections.synchronizedSet(new LinkedHashSet()); private final List probeListeners = new ArrayList<>(); @@ -257,9 +260,13 @@ } /** - * Enables instrumentation at selected nodes in all subsequently constructed ASTs. + * Enables instrumentation at selected nodes in all subsequently constructed ASTs. Ignored if + * the argument is already registered, runtime error if argument is {@code null}. */ public void registerASTProber(ASTProber prober) { + if (prober == null) { + throw new IllegalArgumentException("Register non-null ASTProbers"); + } astProbers.add(prober); }