Java Code Examples for com.oracle.truffle.api.source.Source#getName()

The following examples show how to use com.oracle.truffle.api.source.Source#getName() . 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: SourceMapping.java    From nodeprof.js with Apache License 2.0 6 votes vote down vote up
@TruffleBoundary
public static DynamicObject getJSObjectForSource(Source source) {
    if (source == null) {
        return Undefined.instance;
    }
    JSContext ctx = GlobalObjectCache.getInstance().getJSContext();
    DynamicObject o = JSUserObject.create(ctx);
    String srcName = source.getName();
    if (isEval(source)) {
        String evalSrc = innerMostEvalSource(source.getName());
        if (evalSrc != null) {
            // strip :line:column from source name
            srcName = evalSrc.split(":")[0];
        } else {
            Logger.error("Failed to parse eval source: " + source.getName());
        }
        // 'eval' property signals the source is an eval-string, it contains the full eval hint
        JSObject.set(o, "eval", source.getName());
    }
    JSObject.set(o, "name", shortPath(srcName));
    JSObject.set(o, "internal", isInternal(source));
    return o;
}
 
Example 2
Source File: MumblerReadException.java    From mumbler with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Throwable fillInStackTrace() {
    SourceSection sourceSection = this.getSourceSection();
    Source source = sourceSection != null ? sourceSection.getSource() : null;
    String sourceName = source != null ? source.getName() : null;
    int lineNumber;
    try {
        lineNumber = sourceSection != null ? sourceSection.getStartLine() : -1;
    } catch (UnsupportedOperationException e) {
        /*
         * SourceSection#getLineLocation() may throw an UnsupportedOperationException.
         */
        lineNumber = -1;
    }
    StackTraceElement[] traces = new StackTraceElement[] {
            new StackTraceElement(filename(sourceName),
                    this.getMethodName(),
                    sourceName,
                    lineNumber)
    };
    this.setStackTrace(traces);
    return this;
}
 
Example 3
Source File: SourcePosition.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public SourcePosition(SourceSection sourceSection) {
    Source source = sourceSection.getSource();
    this.id = getId(source);
    this.name = source.getName();
    String sourcePath = source.getPath();
    if (sourcePath == null) {
        sourcePath = name;
    }
    this.path = sourcePath;
    this.sourceSection = sourceSection.getStartLine() + "," + sourceSection.getStartColumn() + "," + sourceSection.getEndLine() + "," + sourceSection.getEndColumn();
    this.code = source.getCharacters().toString();
    this.uri = source.getURI();
}
 
Example 4
Source File: AnalysisFilterSourceList.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
@Override
@TruffleBoundary
public boolean test(final Source source) {
    // don't try to instrument other languages
    if (isForeignSource(source)) {
        return false;
    }

    // if it's an exclusion filter, we include the source by default
    boolean res = filterExcludes;

    boolean isInternal = SourceMapping.isInternal(source);
    // use name or path of source depending whether we consider it internal

    boolean isEval = SourceMapping.isEval(source);
    boolean isIndirectEval = source.getName().startsWith(Evaluator.FUNCTION_SOURCE_NAME) && !matchSources.contains(Evaluator.FUNCTION_SOURCE_NAME);

    String name;
    if (isEval) {
        name = source.getName();
        String sourceOfEval = SourceMapping.innerMostEvalSource(name);
        if (sourceOfEval != null) {
            name = sourceOfEval.split(":")[0];
            // TODO, currently there is no way to judge if the eval is called from internal
            // for the moment, we assume it's not internal
            isInternal = false;
        }
    } else if (isIndirectEval) {
        name = source.getName();
        isInternal = false;
    } else if (isInternal) {
        name = source.getName();
    } else {
        name = source.getPath();
    }
    assert (name != null);

    if (instrumentInternal || !isInternal) {
        // log warning if source does not have a name
        if (name.equals("")) {
            if (logSource(source)) {
                Logger.warning("Source filter: ignoring source without name");
            }
        } else {
            // match against included/excluded sources
            for (final String str : matchSources) {
                if (name.contains(str)) {
                    // apply filter
                    res = !filterExcludes;
                    break;
                }
            }
            if (res && containsDoNotInstrument(source)) {
                res = false;
                if (logSource(source)) {
                    Logger.debug("Source filter: " + logName(name, isInternal) + " -> excluded due to 'DO NOT INSTRUMENT'" + (this.debugHint.isEmpty() ? "" : (" " + this.debugHint)));
                }
            }
        }
    } else {
        // not instrumenting internal source
        res = false;
    }

    if (res && logSource(source)) {
        Logger.debug("Source filter: " + logName(name, isInternal) + " -> included " + (this.debugHint.isEmpty() ? "" : (" " + this.debugHint)));
    }

    // debug log (once per source) if filter did something
    if (logSource(source)) {
        // don't log internal if they are being excluded (there are a lot of them)
        if (instrumentInternal || !isInternal) {
            Logger.debug("Source filter: " + logName(name, isInternal) + " -> " + (res ? "included" : "excluded") + (this.debugHint.isEmpty() ? "" : (" " + this.debugHint)));
        }
    }
    return res;
}
 
Example 5
Source File: AnalysisFilterJS.java    From nodeprof.js with Apache License 2.0 4 votes vote down vote up
@Override
@TruffleBoundary
public boolean test(final Source source) {
    if (isForeignSource(source) || excludedSources.contains(source)) {
        return false;
    }
    if (includedSources.containsKey(source)) {
        return true;
    }

    boolean include = true;

    String name;
    if (SourceMapping.isInternal(source)) {
        name = source.getName();
    } else {
        name = source.getPath();
    }

    Logger.debug("JS Analysis filter testing: " + name + (SourceMapping.isInternal(source) ? " (internal)" : ""));

    if (include && containsDoNotInstrument(source)) {
        include = false;
        Logger.debug("JS Analysis filter: " + name + " -> excluded due to 'DO NOT INSTRUMENT'");
    }

    // we need to bail out during builtin calls inside the JS predicate
    if (include && isRecursive) {
        if (!(name.equals("<builtin>") || name.equals("<internal>"))) {
            Logger.error("JS Analysis filter bailout due to recursive call while testing: " + name);
        }
        return false;
    }

    EnumSet<ProfiledTagEnum> includeTags = allTags;

    if (include) {

        // prevent JS predicate being entered more than once
        isRecursive = true;

        try {
            Object ret = InteropLibrary.getFactory().getUncached().execute(jsPredicateFunc, SourceMapping.getJSObjectForSource(source));
            if (JSArray.isJSArray(ret)) {
                include = JSAbstractArray.arrayGetLength((DynamicObject) ret) > 0;
                includeTags = mapToTags(JSAbstractArray.toArray((DynamicObject) ret));
            } else {
                include = JSRuntime.toBoolean(ret);
            }
        } catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
            Logger.error("JS Analysis filter: call to JS predicate failed");
            Thread.dumpStack();
            System.exit(-1);
        }

        isRecursive = false;

        String tagStr = "";
        if (includeTags != allTags) {
            tagStr = " " + includeTags.toString();
        }
        Logger.debug("JS Analysis filter: " + name + " -> " + (include ? "included" : "excluded") + tagStr);

    }

    if (include) {
        includedSources.put(source, includeTags);
    } else {
        excludedSources.add(source);
    }

    return include;
}