Mercurial > hg > truffle
changeset 22217:7c8c03389f0f
Truffle/Instrumentation: fix bug in registration of ASTProbers
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 15 Sep 2015 14:49:24 -0700 |
parents | daaebd13b27a |
children | f47b601edbc6 |
files | truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java |
diffstat | 2 files changed, 12 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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<ASTProber> astProbers = new ArrayList<>(); + private final Set<ASTProber> astProbers = Collections.synchronizedSet(new LinkedHashSet<ASTProber>()); private final List<ProbeListener> 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); }