comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumenter.java @ 22240:f78c72e2e0b6

Truffle/Instrumentation: clean up, better encapsulate how the application of ASTProbers is managed - Guest Language RootNode implementations no longer involved - ASTProbers are now applied only to RootNodes - Methods renamed to clarify flow of control - Allowed removal of one Accessor instance - Remove tracing overhead when there are no ASTProbers registered
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 22 Sep 2015 20:25:58 -0700
parents df222c4e9bd9
children c1c9c6d79f40
comparison
equal deleted inserted replaced
22239:e7e3826801d6 22240:f78c72e2e0b6
561 // TODO (mlvdv) build this in as a VM event? 561 // TODO (mlvdv) build this in as a VM event?
562 /** 562 /**
563 * Enables instrumentation in a newly created AST by applying all registered instances of 563 * Enables instrumentation in a newly created AST by applying all registered instances of
564 * {@link ASTProber}. 564 * {@link ASTProber}.
565 */ 565 */
566 private void applyInstrumentation(Node node) { 566 private void probeAST(RootNode rootNode) {
567 567 if (!astProbers.isEmpty()) {
568 String name = "<?>"; 568
569 final Source source = findSource(node); 569 String name = "<?>";
570 if (source != null) { 570 final Source source = findSource(rootNode);
571 name = source.getShortName(); 571 if (source != null) {
572 } else { 572 name = source.getShortName();
573 final SourceSection sourceSection = node.getEncapsulatingSourceSection(); 573 } else {
574 if (sourceSection != null) { 574 final SourceSection sourceSection = rootNode.getEncapsulatingSourceSection();
575 name = sourceSection.getShortDescription(); 575 if (sourceSection != null) {
576 } 576 name = sourceSection.getShortDescription();
577 } 577 }
578 trace("START %s", name); 578 }
579 for (ProbeListener listener : probeListeners) { 579 trace("START %s", name);
580 listener.startASTProbing(source); 580 for (ProbeListener listener : probeListeners) {
581 } 581 listener.startASTProbing(source);
582 for (ASTProber prober : astProbers) { 582 }
583 prober.probeAST(this, node); // TODO (mlvdv) 583 for (ASTProber prober : astProbers) {
584 } 584 prober.probeAST(this, rootNode); // TODO (mlvdv)
585 for (ProbeListener listener : probeListeners) { 585 }
586 listener.endASTProbing(source); 586 for (ProbeListener listener : probeListeners) {
587 } 587 listener.endASTProbing(source);
588 trace("FINISHED %s", name); 588 }
589 trace("FINISHED %s", name);
590 }
589 } 591 }
590 592
591 static final class AccessorInstrument extends Accessor { 593 static final class AccessorInstrument extends Accessor {
592 594
593 @Override 595 @Override
616 protected Class<? extends TruffleLanguage> findLanguage(Probe probe) { 618 protected Class<? extends TruffleLanguage> findLanguage(Probe probe) {
617 return probe.getLanguage(); 619 return probe.getLanguage();
618 } 620 }
619 621
620 @Override 622 @Override
621 protected void applyInstrumentation(Node node) { 623 protected void probeAST(RootNode rootNode) {
622 super.getInstrumenter(null).applyInstrumentation(node); 624 // Normally null vm argument; can be reflectively set for testing
625 super.getInstrumenter(testVM).probeAST(rootNode);
623 } 626 }
624 } 627 }
625 628
626 static final AccessorInstrument ACCESSOR = new AccessorInstrument(); 629 static final AccessorInstrument ACCESSOR = new AccessorInstrument();
627 630
631 // Normally null; set for testing where the Accessor hasn't been fully initialized
632 private static Object testVM = null;
633
628 } 634 }