jdk.jfr.internal.PrivateAccess Java Examples

The following examples show how to use jdk.jfr.internal.PrivateAccess. 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: PrettyWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void printField(int commentIndex, ValueDescriptor v) throws IOException {
    println();
    printAnnotations(commentIndex, v.getAnnotationElements());
    printIndent();
    Type vType = PrivateAccess.getInstance().getType(v);
    if (Type.SUPER_TYPE_SETTING.equals(vType.getSuperType())) {
        print("static ");
    }
    print(makeSimpleType(v.getTypeName()));
    if (v.isArray()) {
        print("[]");
    }
    print(" ");
    print(v.getName());
    print(";");
    printCommentRef(commentIndex, v.getTypeId());
}
 
Example #2
Source File: DCmdDump.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute JFR.dump.
 *
 * @param recordingText name or id of the recording to dump, or
 *        <code>null</code>
 *
 * @param textPath file path where recording should be written.
 *
 * @return result output
 *
 * @throws DCmdException if the dump could not be completed
 */
public String execute(String recordingText, String textPath,  Boolean pathToGcRoots) throws DCmdException {
    if (textPath == null) {
        throw new DCmdException("Failed to dump %s, missing filename.", recordingText);
    }
    Recording recording = findRecording(recordingText);
    try {
        SafePath dumpFile = resolvePath(textPath, "Failed to dump %s");
        // create file for JVM
        Utils.touch(dumpFile.toPath());
        PlatformRecording r = PrivateAccess.getInstance().getPlatformRecording(recording);
        WriteableUserPath wup = new WriteableUserPath(dumpFile.toPath());

        Map<String, String> overlay = new HashMap<>();
        Utils.updateSettingPathToGcRoots(overlay, pathToGcRoots);

        r.copyTo(wup, "Dumped by user", overlay);
        reportOperationComplete("Dumped", recording, dumpFile);
    } catch (IOException | InvalidPathException e) {
        throw new DCmdException("Failed to dump %s. Could not copy recording for dump. %s", recordingText, e.getMessage());
    }
    return getResult();
}
 
Example #3
Source File: PrettyWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void printField(int commentIndex, ValueDescriptor v, boolean first) {
    if (!first) {
        println();
    }
    printAnnotations(commentIndex, v.getAnnotationElements());
    printIndent();
    Type vType = PrivateAccess.getInstance().getType(v);
    if (Type.SUPER_TYPE_SETTING.equals(vType.getSuperType())) {
        print("static ");
    }
    print(makeSimpleType(v.getTypeName()));
    if (v.isArray()) {
        print("[]");
    }
    print(" ");
    print(v.getName());
    print(";");
    printCommentRef(commentIndex, v.getTypeId());
}
 
Example #4
Source File: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void printField(int commentIndex, ValueDescriptor v, boolean first) {
    if (!first) {
        println();
    }
    printAnnotations(commentIndex, v.getAnnotationElements());
    printIndent();
    Type vType = PrivateAccess.getInstance().getType(v);
    if (Type.SUPER_TYPE_SETTING.equals(vType.getSuperType())) {
        print("static ");
    }
    print(makeSimpleType(v.getTypeName()));
    if (v.isArray()) {
        print("[]");
    }
    print(" ");
    print(v.getName());
    print(";");
    printCommentRef(commentIndex, v.getTypeId());
}
 
Example #5
Source File: EventHandler.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected EventHandler(boolean registered, EventType eventType, EventControl eventControl) {
    if (System.getSecurityManager() != null) {
        // Do not allow user subclasses when security is enforced.
        if (EventHandler.class.getClassLoader() != this.getClass().getClassLoader()) {
            throw new SecurityException("Illegal subclass");
        }
    }
    this.eventType = eventType;
    this.platformEventType = PrivateAccess.getInstance().getPlatformEventType(eventType);
    this.eventControl = eventControl;
    platformEventType.setRegistered(registered);
}
 
Example #6
Source File: DCmdDump.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private PlatformRecording newSnapShot(PlatformRecorder recorder, Recording recording, Boolean pathToGcRoots) throws DCmdException, IOException {
    if (recording == null) {
        // Operate on all recordings
        PlatformRecording snapshot = recorder.newTemporaryRecording();
        recorder.fillWithRecordedData(snapshot, pathToGcRoots);
        return snapshot;
    }

    PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording);
    return pr.newSnapshotClone("Dumped by user", pathToGcRoots);
}
 
Example #7
Source File: EventHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected EventHandler(boolean registered, EventType eventType, EventControl eventControl) {
    if (System.getSecurityManager() != null) {
        // Do not allow user subclasses when security is enforced.
        if (EventHandler.class.getClassLoader() != this.getClass().getClassLoader()) {
            throw new SecurityException("Illegal subclass");
        }
    }
    this.eventType = eventType;
    this.platformEventType = PrivateAccess.getInstance().getPlatformEventType(eventType);
    this.eventControl = eventControl;
    platformEventType.setRegistered(registered);
}
 
Example #8
Source File: JFCParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static Configuration createConfiguration(String name, String content) throws IOException, ParseException {
    try {
        JFCParserHandler ch = new JFCParserHandler();
        parseXML(content, ch);
        return PrivateAccess.getInstance().newConfiguration(name, ch.label, ch.description, ch.provider, ch.settings, content);
    } catch (IllegalArgumentException iae) {
        throw new ParseException(iae.getMessage(), -1);
    } catch (SAXException e) {
        ParseException pe =  new ParseException("Error reading JFC file. " + e.getMessage(), -1);
        pe.initCause(e);
        throw pe;
    }
}
 
Example #9
Source File: ParserFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Parser createParser(ValueDescriptor v) throws IOException {
    boolean constantPool = PrivateAccess.getInstance().isConstantPool(v);
    if (v.isArray()) {
        Type valueType = PrivateAccess.getInstance().getType(v);
        ValueDescriptor element = PrivateAccess.getInstance().newValueDescriptor(v.getName(), valueType, v.getAnnotationElements(), 0, constantPool, null);
        return new ArrayParser(createParser(element));
    }
    long id = v.getTypeId();
    Type type = types.get(id);
    if (type == null) {
        throw new IOException("Type '" + v.getTypeName() + "' is not defined");
    }
    if (constantPool) {
        ConstantMap pool = constantPools.get(id);
        if (pool == null) {
            pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName());
            constantPools.put(id, pool);
        }
        return new ConstantMapValueParser(pool);
    }
    Parser parser = parsers.get(id);
    if (parser == null) {
        if (!v.getFields().isEmpty()) {
            return createCompositeParser(type);
        } else {
            return registerParserType(type, createPrimitiveParser(type));
        }
    }
    return parser;
}
 
Example #10
Source File: DCmdDump.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private PlatformRecording newSnapShot(PlatformRecorder recorder, Recording recording, Boolean pathToGcRoots) throws DCmdException, IOException {
    if (recording == null) {
        // Operate on all recordings
        PlatformRecording snapshot = recorder.newTemporaryRecording();
        recorder.fillWithRecordedData(snapshot, pathToGcRoots);
        return snapshot;
    }

    PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording);
    return pr.newSnapshotClone("Dumped by user", pathToGcRoots);
}
 
Example #11
Source File: ParserFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Parser createParser(ValueDescriptor v) throws IOException {
    boolean constantPool = PrivateAccess.getInstance().isConstantPool(v);
    if (v.isArray()) {
        Type valueType = PrivateAccess.getInstance().getType(v);
        ValueDescriptor element = PrivateAccess.getInstance().newValueDescriptor(v.getName(), valueType, v.getAnnotationElements(), 0, constantPool, null);
        return new ArrayParser(createParser(element));
    }
    long id = v.getTypeId();
    Type type = types.get(id);
    if (type == null) {
        throw new IOException("Type '" + v.getTypeName() + "' is not defined");
    }
    if (constantPool) {
        ConstantMap pool = constantPools.get(id);
        if (pool == null) {
            pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName());
            constantPools.put(id, pool);
        }
        return new ConstantMapValueParser(pool);
    }
    Parser parser = parsers.get(id);
    if (parser == null) {
        if (!v.getFields().isEmpty()) {
            return createCompositeParser(type);
        } else {
            return registerParserType(type, createPrimitiveParser(type));
        }
    }
    return parser;
}
 
Example #12
Source File: JFCParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static Configuration createConfiguration(String name, String content) throws IOException, ParseException {
    try {
        JFCParserHandler ch = new JFCParserHandler();
        parseXML(content, ch);
        return PrivateAccess.getInstance().newConfiguration(name, ch.label, ch.description, ch.provider, ch.settings, content);
    } catch (IllegalArgumentException iae) {
        throw new ParseException(iae.getMessage(), -1);
    } catch (SAXException e) {
        ParseException pe =  new ParseException("Error reading JFC file. " + e.getMessage(), -1);
        pe.initCause(e);
        throw pe;
    }
}
 
Example #13
Source File: ParserFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Parser createParser(ValueDescriptor v) throws IOException {
    boolean constantPool = PrivateAccess.getInstance().isConstantPool(v);
    if (v.isArray()) {
        Type valueType = PrivateAccess.getInstance().getType(v);
        ValueDescriptor element = PrivateAccess.getInstance().newValueDescriptor(v.getName(), valueType, v.getAnnotationElements(), 0, constantPool, null);
        return new ArrayParser(createParser(element));
    }
    long id = v.getTypeId();
    Type type = types.get(id);
    if (type == null) {
        throw new IOException("Type '" + v.getTypeName() + "' is not defined");
    }
    if (constantPool) {
        ConstantMap pool = constantPools.get(id);
        if (pool == null) {
            pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName());
            constantPools.put(id, pool);
        }
        return new ConstantMapValueParser(pool);
    }
    Parser parser = parsers.get(id);
    if (parser == null) {
        if (!v.getFields().isEmpty()) {
            return createCompositeParser(type);
        } else {
            return registerParserType(type, createPrimitiveParser(type));
        }
    }
    return parser;
}
 
Example #14
Source File: JFCParser.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static Configuration createConfiguration(String name, String content) throws IOException, ParseException {
    try {
        JFCParserHandler ch = new JFCParserHandler();
        parseXML(content, ch);
        return PrivateAccess.getInstance().newConfiguration(name, ch.label, ch.description, ch.provider, ch.settings, content);
    } catch (IllegalArgumentException iae) {
        throw new ParseException(iae.getMessage(), -1);
    } catch (SAXException e) {
        ParseException pe =  new ParseException("Error reading JFC file. " + e.getMessage(), -1);
        pe.initCause(e);
        throw pe;
    }
}
 
Example #15
Source File: DCmdDump.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Execute JFR.dump.
 *
 * @param name name or id of the recording to dump, or <code>null</code> to dump everything
 *
 * @param filename file path where recording should be written, not null
 * @param maxAge how far back in time to dump, may be null
 * @param maxSize how far back in size to dump data from, may be null
 * @param begin point in time to dump data from, may be null
 * @param end point in time to dump data to, may be null
 * @param pathToGcRoots if Java heap should be swept for reference chains
 *
 * @return result output
 *
 * @throws DCmdException if the dump could not be completed
 */
public String execute(String name, String filename, Long maxAge, Long maxSize, String begin, String end, Boolean pathToGcRoots) throws DCmdException {
    if (LogTag.JFR_DCMD.shouldLog(LogLevel.DEBUG)) {
        Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG,
                "Executing DCmdDump: name=" + name +
                ", filename=" + filename +
                ", maxage=" + maxAge +
                ", maxsize=" + maxSize +
                ", begin=" + begin +
                ", end" + end +
                ", path-to-gc-roots=" + pathToGcRoots);
    }

    if (FlightRecorder.getFlightRecorder().getRecordings().isEmpty()) {
        throw new DCmdException("No recordings to dump from. Use JFR.start to start a recording.");
    }

    if (maxAge != null) {
        if (end != null || begin != null) {
            throw new DCmdException("Dump failed, maxage can't be combined with begin or end.");
        }

        if (maxAge < 0) {
            throw new DCmdException("Dump failed, maxage can't be negative.");
        }
        if (maxAge == 0) {
            maxAge = Long.MAX_VALUE / 2; // a high value that won't overflow
        }
    }

    if (maxSize!= null) {
        if (maxSize < 0) {
            throw new DCmdException("Dump failed, maxsize can't be negative.");
        }
        if (maxSize == 0) {
            maxSize = Long.MAX_VALUE / 2; // a high value that won't overflow
        }
    }

    Instant beginTime = parseTime(begin, "begin");
    Instant endTime = parseTime(end, "end");

    if (beginTime != null && endTime != null) {
        if (endTime.isBefore(beginTime)) {
            throw new DCmdException("Dump failed, begin must preceed end.");
        }
    }

    Duration duration = null;
    if (maxAge != null) {
        duration = Duration.ofNanos(maxAge);
        beginTime = Instant.now().minus(duration);
    }
    Recording recording = null;
    if (name != null) {
        recording = findRecording(name);
    }
    PlatformRecorder recorder = PrivateAccess.getInstance().getPlatformRecorder();
    synchronized (recorder) {
        dump(recorder, recording, name, filename, maxSize, pathToGcRoots, beginTime, endTime);
    }
    return getResult();
}
 
Example #16
Source File: EventHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
EventHandler(boolean registered, EventType eventType, EventControl eventControl) {
    this.eventType = eventType;
    this.platformEventType = PrivateAccess.getInstance().getPlatformEventType(eventType);
    this.eventControl = eventControl;
    platformEventType.setRegistered(registered);
}
 
Example #17
Source File: DCmdDump.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Execute JFR.dump.
 *
 * @param name name or id of the recording to dump, or <code>null</code> to dump everything
 *
 * @param filename file path where recording should be written, not null
 * @param maxAge how far back in time to dump, may be null
 * @param maxSize how far back in size to dump data from, may be null
 * @param begin point in time to dump data from, may be null
 * @param end point in time to dump data to, may be null
 * @param pathToGcRoots if Java heap should be swept for reference chains
 *
 * @return result output
 *
 * @throws DCmdException if the dump could not be completed
 */
public String execute(String name, String filename, Long maxAge, Long maxSize, String begin, String end, Boolean pathToGcRoots) throws DCmdException {
    if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
        Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG,
                "Executing DCmdDump: name=" + name +
                ", filename=" + filename +
                ", maxage=" + maxAge +
                ", maxsize=" + maxSize +
                ", begin=" + begin +
                ", end" + end +
                ", path-to-gc-roots=" + pathToGcRoots);
    }

    if (FlightRecorder.getFlightRecorder().getRecordings().isEmpty()) {
        throw new DCmdException("No recordings to dump from. Use JFR.start to start a recording.");
    }

    if (maxAge != null) {
        if (end != null || begin != null) {
            throw new DCmdException("Dump failed, maxage can't be combined with begin or end.");
        }

        if (maxAge < 0) {
            throw new DCmdException("Dump failed, maxage can't be negative.");
        }
        if (maxAge == 0) {
            maxAge = Long.MAX_VALUE / 2; // a high value that won't overflow
        }
    }

    if (maxSize!= null) {
        if (maxSize < 0) {
            throw new DCmdException("Dump failed, maxsize can't be negative.");
        }
        if (maxSize == 0) {
            maxSize = Long.MAX_VALUE / 2; // a high value that won't overflow
        }
    }

    Instant beginTime = parseTime(begin, "begin");
    Instant endTime = parseTime(end, "end");

    if (beginTime != null && endTime != null) {
        if (endTime.isBefore(beginTime)) {
            throw new DCmdException("Dump failed, begin must preceed end.");
        }
    }

    Duration duration = null;
    if (maxAge != null) {
        duration = Duration.ofNanos(maxAge);
        beginTime = Instant.now().minus(duration);
    }
    Recording recording = null;
    if (name != null) {
        recording = findRecording(name);
    }
    PlatformRecorder recorder = PrivateAccess.getInstance().getPlatformRecorder();
    synchronized (recorder) {
        dump(recorder, recording, name, filename, maxSize, pathToGcRoots, beginTime, endTime);
    }
    return getResult();
}