com.oracle.truffle.api.instrumentation.EventContext Java Examples

The following examples show how to use com.oracle.truffle.api.instrumentation.EventContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BranchCoverage.java    From nodeprof.js with Apache License 2.0 6 votes vote down vote up
@Override
public void initCallbacks() {
    this.onCallback(ProfiledTagEnum.CF_BRANCH, new AnalysisFactory<BaseEventHandlerNode>() {
        @Override
        public BaseEventHandlerNode create(EventContext context) {
            return new ConditionalEventHandler(context) {

                @Child ReportEntryNode trueCounter = ReportEntryNodeGen.create(trueDB, new SimpleCounterReport.SimleReportFactory());
                @Child ReportEntryNode falseCounter = ReportEntryNodeGen.create(falseDB, new SimpleCounterReport.SimleReportFactory());

                @Override
                public void executePost(VirtualFrame frame, Object result, Object[] inputs) {
                    if (JSRuntime.toBoolean(result)) {
                        addDebugEvent("BC", getSourceIID(), ProfiledTagEnum.CF_BRANCH, true);
                        ((SimpleCounterReport) (trueCounter.execute(getSourceIID()))).incre();
                    } else {
                        addDebugEvent("BC", getSourceIID(), ProfiledTagEnum.CF_BRANCH, false);
                        ((SimpleCounterReport) (falseCounter.execute(getSourceIID()))).incre();
                    }
                }
            };
        }
    });
}
 
Example #2
Source File: LiteralFactory.java    From nodeprof.js with Apache License 2.0 6 votes vote down vote up
@Override
public BaseEventHandlerNode create(EventContext context) {
    return new LiteralEventHandler(context) {
        private final boolean skip = !types.contains(LiteralTag.Type.valueOf(getLiteralType()));
        @Node.Child private InteropLibrary postDispatch = (post == null) ? null : createDispatchNode();

        @Override
        public void executePost(VirtualFrame frame, Object result,
                        Object[] inputs) throws InteropException {
            if (post != null && !skip) {
                wrappedDispatchExecution(this, postDispatch, post, getSourceIID(), convertResult(result), Undefined.instance, getLiteralType());
            }
        }

    };
}
 
Example #3
Source File: DeclareFactory.java    From nodeprof.js with Apache License 2.0 6 votes vote down vote up
@Override
public BaseEventHandlerNode create(EventContext context) {
    return new DeclareEventHandler(context) {
        @Node.Child private InteropLibrary postDispatch = (post == null) ? null : createDispatchNode();

        @Override
        public void executePost(VirtualFrame frame, Object result,
                        Object[] inputs) throws InteropException {
            if (post != null) {
                checkForSymbolicLocation(context.getInstrumentedNode(), frame.getArguments());

                wrappedDispatchExecution(this, postDispatch, post, getSourceIID(), getDeclareName(), getDeclareType());
            }
        }

    };
}
 
Example #4
Source File: ProfilerExecutionEventNode.java    From nodeprof.js with Apache License 2.0 6 votes vote down vote up
@Override
protected void onInputValue(VirtualFrame frame, EventContext inputContext,
                int inputIndex, Object inputValue) {
    if (!profilerEnabled) {
        return;
    }
    if (child.expectedNumInputs() < 0 || inputIndex < child.expectedNumInputs()) {
        // save input only necessary
        saveInputValue(frame, inputIndex, inputValue);
    }
    if (this.child.isLastIndex(getInputCount(), inputIndex)) {
        this.cb.preHitCount++;
        try {
            this.child.executePre(frame, child.expectedNumInputs() != 0 ? getSavedInputValues(frame) : null);

            // allow for handler changes after executePre/Post
            checkHandlerChanges();
        } catch (Throwable e) {
            reportError(null, e);
        }
    }
}
 
Example #5
Source File: CountObjectAllocation.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@Override
public void initCallbacks() {
    this.onCallback(ProfiledTagEnum.LITERAL, new AnalysisFactory<BaseEventHandlerNode>() {

        @Override
        public BaseEventHandlerNode create(EventContext context) {
            return new LiteralEventHandler(context) {

                @Child ReportEntryNode getReport = ReportEntryNodeGen.create(db, new SimpleCounterReport.SimleReportFactory());

                @Override
                public void executePost(VirtualFrame frame, Object result,
                                Object[] inputs) {
                    if (this.getLiteralType().equals("ArrayLiteral") || this.equals("ObjectLiteral")) {
                        addDebugEvent("OBJ-LIT", getSourceIID(), ProfiledTagEnum.LITERAL);
                        SimpleCounterReport report = (SimpleCounterReport) (getReport.execute(this.getSourceIID()));
                        report.incre();
                    }
                }
            };
        }
    });

    this.onCallback(ProfiledTagEnum.INVOKE, getInvokeOrNewFactory(true));

    this.onCallback(ProfiledTagEnum.NEW, getInvokeOrNewFactory(false));

}
 
Example #6
Source File: DebugInstrument.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(final Env env) {
    instrumenter = env.getInstrumenter();
    env.registerService(this);
    SourceSectionFilter sourceSectionFilter = SourceSectionFilter.newBuilder().tagIs(JSTags.ALL).build();
    // What generates the input events to track?
    SourceSectionFilter inputGeneratingObjects = SourceSectionFilter.newBuilder().tagIs(
                    StandardTags.ExpressionTag.class,
                    StandardTags.StatementTag.class,
                    InputNodeTag.class).build();
    env.getInstrumenter().attachExecutionEventFactory(sourceSectionFilter, inputGeneratingObjects, new ExecutionEventNodeFactory() {
        public ExecutionEventNode create(EventContext context) {
            // TODO Auto-generated method stub
            return new ExecutionEventNode() {
                @Node.Child private InteropLibrary dispatch = InteropLibrary.getFactory().createDispatched(5);

                @TruffleBoundary
                @Override
                public void onEnter(VirtualFrame frame) {
                    /*
                     * Internal sources are executed at engine startup time. Such sources
                     * include internal code for the registration of builtins like Promise. We
                     * skip all these internal events to ensure that tests are deterministic.
                     */
                    DynamicObject func = (DynamicObject) frame.getArguments()[1];
                    try {
                        dispatch.execute(JSFunction.createEmptyFunction(JSObject.getJSContext(func).getRealm()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
        }
    });
}
 
Example #7
Source File: FunctionRootEventHandler.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
public FunctionRootEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.ROOT);
    if (isBuiltin) {
        builtinName = getAttribute("name").toString();
    } else {
        builtinName = null;
    }
}
 
Example #8
Source File: FunctionCallEventHandler.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
public FunctionCallEventHandler(EventContext context, ProfiledTagEnum tag) {
    super(context, tag);
    // tag should be either NEW or INVOKE
    assert tag == ProfiledTagEnum.INVOKE || tag == ProfiledTagEnum.NEW;
    this.isInvoke = (boolean) getAttribute("isInvoke");
    this.isNew = (boolean) getAttribute("isNew");
}
 
Example #9
Source File: ExpressionEventHandler.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@TruffleBoundary
public ExpressionEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.EXPRESSION);
    String nodeName = context.getInstrumentedNode().getClass().getSimpleName();
    // TODO, use more abstract types instead in future, e.g., similar to ESTree
    // currently, use the instrumented node's type (slightly trimmed)
    if (nodeName.lastIndexOf("Node") > 0) {
        this.expressionType = nodeName.substring(0, nodeName.lastIndexOf("Node"));
    } else {
        this.expressionType = nodeName;
    }
}
 
Example #10
Source File: TypedArray.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
private AnalysisFactory<BaseEventHandlerNode> getInvokeOrNewFactory(boolean isInvoke) {
    ProfiledTagEnum tag = isInvoke ? ProfiledTagEnum.INVOKE : ProfiledTagEnum.NEW;
    return new AnalysisFactory<BaseEventHandlerNode>() {
        @Override
        public BaseEventHandlerNode create(
                        EventContext context) {
            return new FunctionCallEventHandler(context, tag) {
                @Child ReportEntryNode getReportNode = ReportEntryNodeGen.create(db, new TypedArrayFactory());

                @Child IsArrayFunctionNode arrayFunc = IsArrayFunctionNodeGen.create();

                @Override
                public void executePost(VirtualFrame frame,
                                Object result, Object[] inputs) {
                    Object funcObj = getFunction(inputs);
                    if (funcObj instanceof DynamicObject) {
                        Object constructor = GlobalObjectCache.getInstance().getArrayConstructor((DynamicObject) funcObj);
                        if (funcObj == constructor) {
                            trackAllocation(result, getSourceIID());
                            addDebugEvent("TA_ARRAY_ALLOC", getSourceIID(), tag);
                            getReportNode.execute(this.getSourceIID());
                        }
                    }
                }
            };
        }
    };
}
 
Example #11
Source File: InitialRootFactory.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@Override
public BaseEventHandlerNode create(EventContext context) {
    return new FunctionRootEventHandler(context) {
        @Node.Child private InteropLibrary postDispatch = (post == null) ? null : createDispatchNode();

        @Override
        public int getPriority() {
            return -1;
        }

        @Override
        public BaseEventHandlerNode wantsToUpdateHandler() {
            // remove after initial execution
            return null;
        }

        @Override
        public void executePre(VirtualFrame frame, Object[] inputs) throws InteropException {
            checkForSymbolicLocation(context.getInstrumentedNode(), getArguments(frame));

            if (post == null) {
                return;
            }

            Source source = getSource();
            if (source == null) {
                return;
            }

            if (isNewSource(source)) {
                wrappedDispatchExecution(this, postDispatch, post,
                                SourceMapping.getJSObjectForSource(source), // arg 1: source
                                                                            // object
                                source.getCharacters().toString()); // arg 2: source code
            }
        }
    };
}
 
Example #12
Source File: ForObjectFactory.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@Override
public BaseEventHandlerNode create(EventContext context) {
    return new LoopEventHandler(context) {
        @Node.Child private InteropLibrary preDispatch = (pre == null) ? null : createDispatchNode();

        @Override
        public void executePre(VirtualFrame frame,
                        Object[] inputs) throws InteropException {
            if (pre != null && (isForIn() || isForOf())) {
                wrappedDispatchExecution(this, preDispatch, pre, getSourceIID(), isForIn());
            }
        }
    };
}
 
Example #13
Source File: ProfilerExecutionEventNode.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
public ProfilerExecutionEventNode(ProfiledTagEnum cb, EventContext context,
                BaseEventHandlerNode child) {
    this.context = context;
    this.cb = cb;
    this.cb.nodeCount++;
    this.child = child;
}
 
Example #14
Source File: BaseSingleTagEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public BaseSingleTagEventHandler(EventContext context, ProfiledTagEnum tag) {
    super(context);
    this.tag = tag;
}
 
Example #15
Source File: ConditionalEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public ConditionalEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.CF_BRANCH);
    boolean typeIsCond = false;
    typeIsCond = JSTags.ControlFlowBranchTag.Type.Condition.name().equals(getAttributeNoReport("type"));
    this.isConditional = typeIsCond;
}
 
Example #16
Source File: VarWriteEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public VarWriteEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.VAR_WRITE);
}
 
Example #17
Source File: LiteralEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public LiteralEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.LITERAL);
    this.literalType = (String) getAttribute(LiteralTag.TYPE);
}
 
Example #18
Source File: CFBranchEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public CFBranchEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.CF_BRANCH);
    this.type = (String) getAttribute("type");
}
 
Example #19
Source File: BinaryEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public BinaryEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.BINARY);
    op = (String) getAttribute("operator");
    isLogic = op.equals("||") || op.equals("&&");
}
 
Example #20
Source File: NonContiguousArray.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
@Override
public void initCallbacks() {
    this.onCallback(ProfiledTagEnum.ELEMENT_WRITE, new AnalysisFactory<BaseEventHandlerNode>() {
        @Override
        public BaseEventHandlerNode create(EventContext context) {
            return new ElementWriteEventHandler(context) {

                @Child ReportEntryNode getReport = ReportEntryNodeGen.create(db, new SimpleCounterReport.SimleReportFactory());

                @Child GetArrayIndexNode toArrayIndex = new GetArrayIndexNode();

                @Child GetArraySizeNode getArraySize = GetArraySizeNodeGen.create();

                @Override
                public void executePre(VirtualFrame frame, Object[] inputs) {
                    if (!JSArray.isJSArray(getReceiver(inputs))) {
                        addDebugEvent("EW_NONARRAY", getSourceIID(), ProfiledTagEnum.ELEMENT_WRITE);
                        return;
                    }

                    Object convertedIndex = toArrayIndex.execute(getProperty(inputs));

                    if (convertedIndex instanceof Long && ((Long) convertedIndex) >= 0) {
                        long idx = (long) convertedIndex;
                        long curSize = getArraySize.executeSize(getReceiver(inputs));

                        addDebugEvent("EW_ARRAY_INT", getSourceIID(), ProfiledTagEnum.ELEMENT_WRITE, idx, curSize);

                        if (idx > curSize) {
                            SimpleCounterReport report = (SimpleCounterReport) getReport.execute(this.getSourceIID());
                            report.incre();
                            addDebugEvent("REPORT", getSourceIID(), ProfiledTagEnum.ELEMENT_WRITE);
                        }
                    } else {
                        addDebugEvent("EW_ARRAY_ELSE", getSourceIID(), ProfiledTagEnum.ELEMENT_WRITE, convertedIndex);
                    }
                }
            };
        }
    });
}
 
Example #21
Source File: VarEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public VarEventHandler(EventContext context, ProfiledTagEnum tag) {
    super(context, tag);
    this.name = (String) getAttribute("name");
}
 
Example #22
Source File: ElementReadEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public ElementReadEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.ELEMENT_READ);
}
 
Example #23
Source File: ElementWriteEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public ElementWriteEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.ELEMENT_WRITE);
}
 
Example #24
Source File: VarReadEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public VarReadEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.VAR_READ);
}
 
Example #25
Source File: PropertyWriteEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public PropertyWriteEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.PROPERTY_WRITE);
    this.property = (String) getAttribute("key");
}
 
Example #26
Source File: LoopEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public LoopEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.CF_ROOT);
}
 
Example #27
Source File: EvalEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public EvalEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.EVAL);
}
 
Example #28
Source File: BuiltinRootEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public BuiltinRootEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.BUILTIN);
    this.builtinName = getAttribute("name").toString();
}
 
Example #29
Source File: UnaryEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public UnaryEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.UNARY);
    op = (String) getAttribute("operator");
    this.isDelete = op.equals("delete");
    this.isVoid = op.equals("void");
}
 
Example #30
Source File: CFRootEventHandler.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
public CFRootEventHandler(EventContext context) {
    super(context, ProfiledTagEnum.CF_ROOT);
    this.type = (String) getAttribute("type");
}