com.oracle.truffle.api.nodes.LanguageInfo Java Examples

The following examples show how to use com.oracle.truffle.api.nodes.LanguageInfo. 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: FrameInfo.java    From netbeans with Apache License 2.0 6 votes vote down vote up
FrameInfo(DebugStackFrame topStackFrame, Iterable<DebugStackFrame> stackFrames) {
    SourceSection topSS = topStackFrame.getSourceSection();
    SourcePosition position = new SourcePosition(topSS);
    ArrayList<DebugStackFrame> stackFramesArray = new ArrayList<>();
    for (DebugStackFrame sf : stackFrames) {
        if (sf == topStackFrame) {
            continue;
        }
        SourceSection ss = sf.getSourceSection();
        // Ignore frames without sources:
        if (ss == null || ss.getSource() == null) {
            continue;
        }
        stackFramesArray.add(sf);
    }
    frame = topStackFrame;
    stackTrace = stackFramesArray.toArray(new DebugStackFrame[stackFramesArray.size()]);
    LanguageInfo sfLang = topStackFrame.getLanguage();
    topFrame = topStackFrame.getName() + "\n" +
               ((sfLang != null) ? sfLang.getId() + " " + sfLang.getName() : "") + "\n" +
               DebuggerVisualizer.getSourceLocation(topSS) + "\n" +
               position.id + "\n" + position.name + "\n" + position.path + "\n" +
               position.uri.toString() + "\n" + position.sourceSection +/* "," + position.startColumn + "," +
               position.endLine + "," + position.endColumn +*/ "\n" + isInternal(topStackFrame);
    topVariables = JPDATruffleAccessor.getVariables(topStackFrame);
}
 
Example #2
Source File: Truffle.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Map<String, Object>[] heapHistogram() {
    Collection<HeapMonitor> all = getAllHeapHistogramInstances();

    for (HeapMonitor histo : all) {
        if (histo.hasData()) {
            Map<LanguageInfo, Map<String, HeapSummary>> info = histo.takeMetaObjectSummary();
            try {
                return toMap(info);
            } catch (Throwable ex) {
                Logger.getLogger(Truffle.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    return new Map[0];
}
 
Example #3
Source File: Truffle.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
Map<String, Object>[] toMap(Map<LanguageInfo, Map<String, HeapSummary>> summaries) throws NoSuchFieldException {
    List<Map<String, Object>> heapHisto = new ArrayList<>(summaries.size());
    for (Map.Entry<LanguageInfo, Map<String, HeapSummary>> objectsByLanguage : summaries.entrySet()) {
        String langId = getLanguageId(objectsByLanguage.getKey());
        for (Map.Entry<String, HeapSummary> objectsByMetaObject : objectsByLanguage.getValue().entrySet()) {
            HeapSummary mi = objectsByMetaObject.getValue();
            Map<String, Object> metaObjMap = new HashMap<>();
            metaObjMap.put("language", langId);
            metaObjMap.put("name", objectsByMetaObject.getKey());
            metaObjMap.put("allocatedInstancesCount", mi.getTotalInstances());
            metaObjMap.put("bytes", mi.getTotalBytes());
            metaObjMap.put("liveInstancesCount", mi.getAliveInstances());
            metaObjMap.put("liveBytes", mi.getAliveBytes());
            heapHisto.add(metaObjMap);
        }
    }
    return heapHisto.toArray(new Map[0]);
}
 
Example #4
Source File: NodeProfInstrument.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@Override
public void onLanguageContextInitialized(TruffleContext context, LanguageInfo language) {

    assert (context != null);
    /**
     * the language context will be created twice at the beginning. in svm the second context is
     * different than the first one while in jvm the second context is the same as the first
     * one. we enable NodeProf after the second one is initilized
     */
    if (GlobalConfiguration.DEBUG_TRACING) {
        RawEventsTracingSupport.enable(instrumenter);
    }
    if (readyToLoad && !loaded) {
        if (GlobalConfiguration.ANALYSIS != null) {
            String[] names = GlobalConfiguration.ANALYSIS.split(",");
            for (String name : names) {
                if (GlobalConfiguration.DEBUG) {
                    Logger.debug("loading " + name + " for analysis");
                }
                NodeProfAnalysis.enableAnalysis(this.instrumenter, instrumentEnv, name);
            }
        }
        loaded = true;
    }
    // ready to load for the second context
    readyToLoad = true;
}
 
Example #5
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization
@TruffleBoundary
protected static final ArrayObject doList(@SuppressWarnings("unused") final Object receiver,
                @Cached final WrapToSqueakNode wrapNode,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    final Collection<LanguageInfo> languages = image.env.getPublicLanguages().values();
    final Object[] result = languages.stream().map(l -> l.getId()).toArray();
    return wrapNode.executeList(result);
}
 
Example #6
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "languageID.isByteType()")
@TruffleBoundary
protected static final ArrayObject doGet(@SuppressWarnings("unused") final Object receiver, final NativeObject languageID,
                @Cached final WrapToSqueakNode wrapNode,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    final Collection<LanguageInfo> languages = image.env.getPublicLanguages().values();
    return wrapNode.executeList(languages.stream().//
                    filter(l -> l.getId().equals(languageID.asStringUnsafe())).//
                    map(l -> new Object[]{l.getId(), l.getName(), l.getVersion(), l.getDefaultMimeType(), l.getMimeTypes().toArray()}).//
                    findFirst().orElseThrow(() -> PrimitiveFailed.GENERIC_ERROR));
}
 
Example #7
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@TruffleBoundary
private static String findLanguageByMimeType(final Env env, final String mimeType) {
    final Map<String, LanguageInfo> languages = env.getPublicLanguages();
    for (final String registeredMimeType : languages.keySet()) {
        if (mimeType.equals(registeredMimeType)) {
            return languages.get(registeredMimeType).getId();
        }
    }
    return null;
}
 
Example #8
Source File: Truffle.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private String getLanguageId(Object lang) throws NoSuchFieldException, SecurityException {
    if (Engine_findActiveEngines != null) {
        return ((LanguageInfo)lang).getId();
    }
    Field f = lang.getClass().getDeclaredField("id");
    String lId = (String) unsafe.getObject(lang, unsafe.objectFieldOffset(f));
    return lId;
}
 
Example #9
Source File: JPDATruffleAccessor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * @param frames The array of stack frame infos
 * @return An array of two elements: a String of frame information and
 * an array of code contents.
 */
static Object[] getFramesInfo(DebugStackFrame[] frames, boolean includeInternal) {
    trace("getFramesInfo({0})",includeInternal);
    int n = frames.length;
    StringBuilder frameInfos = new StringBuilder();
    String[] codes = new String[n];
    Object[] thiss = new Object[n];
    int j = 0;
    for (int i = 0; i < n; i++) {
        DebugStackFrame sf = frames[i];
        boolean isInternal = FrameInfo.isInternal(sf);
        //System.err.println("SF("+sf.getName()+", "+sf.getSourceSection()+") is internal = "+isInternal);
        if (!includeInternal && isInternal) {
            continue;
        }
        String sfName = sf.getName();
        if (sfName == null) {
            sfName = "";
        }
        frameInfos.append(sfName);
        frameInfos.append('\n');
        LanguageInfo sfLang = sf.getLanguage();
        String sfLangId = (sfLang != null) ? sfLang.getId() + " " + sfLang.getName() : "";
        frameInfos.append(sfLangId);
        frameInfos.append('\n');
        frameInfos.append(DebuggerVisualizer.getSourceLocation(sf.getSourceSection()));
        frameInfos.append('\n');
        /*if (fi.getCallNode() == null) {
            /* frames with null call nodes are filtered out by JPDATruffleDebugManager.FrameInfo
            System.err.println("Frame with null call node: "+fi);
            System.err.println("  is virtual frame = "+fi.isVirtualFrame());
            System.err.println("  call target = "+fi.getCallTarget());
            System.err.println("frameInfos = "+frameInfos);
            *//*
        }*/
        SourcePosition position = new SourcePosition(sf.getSourceSection());
        frameInfos.append(createPositionIdentificationString(position));
        if (includeInternal) {
            frameInfos.append('\n');
            frameInfos.append(isInternal);
        }
        
        frameInfos.append("\n\n");
        
        codes[j] = position.code;
        j++;
    }
    if (j < n) {
        codes = Arrays.copyOf(codes, j);
        thiss = Arrays.copyOf(thiss, j);
    }
    boolean areSkippedInternalFrames = j < n;
    return new Object[] { frameInfos.toString(), codes, thiss, areSkippedInternalFrames };
}
 
Example #10
Source File: NodeProfInstrument.java    From nodeprof.js with Apache License 2.0 2 votes vote down vote up
@Override
public void onLanguageContextCreated(TruffleContext context, LanguageInfo language) {

}
 
Example #11
Source File: NodeProfInstrument.java    From nodeprof.js with Apache License 2.0 2 votes vote down vote up
@Override
public void onLanguageContextFinalized(TruffleContext context, LanguageInfo language) {

}
 
Example #12
Source File: NodeProfInstrument.java    From nodeprof.js with Apache License 2.0 2 votes vote down vote up
@Override
public void onLanguageContextDisposed(TruffleContext context, LanguageInfo language) {

}
 
Example #13
Source File: HeapMonitor.java    From visualvm with GNU General Public License v2.0 votes vote down vote up
public Map<LanguageInfo, Map<String, HeapSummary>> takeMetaObjectSummary() {return null;}