Java Code Examples for jdk.jfr.internal.Logger#log()

The following examples show how to use jdk.jfr.internal.Logger#log() . 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: JIMethodCallInliner.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitMethodInsn(int opcode, String owner, String name,
        String desc, boolean itf) {
    // Now we are looking at method call in the source method
    if (!shouldBeInlined(owner, name, desc)) {
        // If this method call should not be inlined, just keep it
        mv.visitMethodInsn(opcode, owner, name, desc, itf);
        return;
    }
    // If the call should be inlined, we create a MethodInliningAdapter
    // The MIA will walk the instructions in the inlineTarget and add them
    // to the current method, doing the necessary name remappings.
    Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.DEBUG, "Inlining call to " + name + desc);
    Remapper remapper = new SimpleRemapper(oldClass, newClass);
    Label end = new Label();
    inlining = true;
    inlineTarget.instructions.resetLabels();
    JIMethodInliningAdapter mia = new JIMethodInliningAdapter(this, end,
            opcode == Opcodes.INVOKESTATIC ? Opcodes.ACC_STATIC : 0, desc,
            remapper);
    inlineTarget.accept(mia);
    inlining = false;
    super.visitLabel(end);
}
 
Example 2
Source File: JIMethodMergeAdapter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitEnd() {
    SimpleRemapper remapper = new SimpleRemapper(typeMap);
    for (MethodNode mn : cn.methods) {
        // Check if the method is in the list of methods to copy
        if (methodInFilter(mn.name, mn.desc)) {
            Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.DEBUG, "Copying method: " + mn.name + mn.desc);
            Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.DEBUG,  "   with mapper: " + typeMap);

            String[] exceptions = new String[mn.exceptions.size()];
            mn.exceptions.toArray(exceptions);
            MethodVisitor mv = cv.visitMethod(mn.access, mn.name, mn.desc, mn.signature, exceptions);
            mn.instructions.resetLabels();
            mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, remapper));
        }
    }
    super.visitEnd();
}
 
Example 3
Source File: JDKEvents.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public static byte[] retransformCallback(Class<?> klass, byte[] oldBytes) throws Throwable {
    if (java.lang.Throwable.class == klass) {
        Logger.log(LogTag.JFR_SYSTEM, LogLevel.TRACE, "Instrumenting java.lang.Throwable");
        return ConstructorTracerWriter.generateBytes(java.lang.Throwable.class, oldBytes);
    }

    if (java.lang.Error.class == klass) {
        Logger.log(LogTag.JFR_SYSTEM, LogLevel.TRACE, "Instrumenting java.lang.Error");
        return ConstructorTracerWriter.generateBytes(java.lang.Error.class, oldBytes);
    }

    for (int i = 0; i < targetClasses.length; i++) {
        if (targetClasses[i].equals(klass)) {
            Class<?> c = instrumentationClasses[i];
            Logger.log(LogTag.JFR_SYSTEM, LogLevel.TRACE, () -> "Processing instrumentation class: " + c);
            return new JIClassInstrumentation(instrumentationClasses[i], klass, oldBytes).getNewBytes();
        }
    }
    return oldBytes;
}
 
Example 4
Source File: JIInliner.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);

    if (isInstrumentationMethod(name, desc)) {
        MethodNode methodToInline = findTargetMethodNode(name, desc);
        if (methodToInline == null) {
            throw new IllegalArgumentException("Could not find the method to instrument in the target class");
        }
        if (Modifier.isNative(methodToInline.access)) {
            throw new IllegalArgumentException("Cannot instrument native methods: " + targetClassNode.name + "." + methodToInline.name + methodToInline.desc);
        }

        Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.DEBUG, "Inliner processing method " + name + desc);

        JIMethodCallInliner mci = new JIMethodCallInliner(access,
                desc,
                mv,
                methodToInline,
                targetClassName,
                instrumentationClassName);
        return mci;
    }

    return mv;
}
 
Example 5
Source File: JIInliner.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);

    if (isInstrumentationMethod(name, desc)) {
        MethodNode methodToInline = findTargetMethodNode(name, desc);
        if (methodToInline == null) {
            throw new IllegalArgumentException("Could not find the method to instrument in the target class");
        }
        if (Modifier.isNative(methodToInline.access)) {
            throw new IllegalArgumentException("Cannot instrument native methods: " + targetClassNode.name + "." + methodToInline.name + methodToInline.desc);
        }

        Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.DEBUG, "Inliner processing method " + name + desc);

        JIMethodCallInliner mci = new JIMethodCallInliner(access,
                desc,
                mv,
                methodToInline,
                targetClassName,
                instrumentationClassName);
        return mci;
    }

    return mv;
}
 
Example 6
Source File: JIMethodCallInliner.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitMethodInsn(int opcode, String owner, String name,
        String desc, boolean itf) {
    // Now we are looking at method call in the source method
    if (!shouldBeInlined(owner, name, desc)) {
        // If this method call should not be inlined, just keep it
        mv.visitMethodInsn(opcode, owner, name, desc, itf);
        return;
    }
    // If the call should be inlined, we create a MethodInliningAdapter
    // The MIA will walk the instructions in the inlineTarget and add them
    // to the current method, doing the necessary name remappings.
    Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.DEBUG, "Inlining call to " + name + desc);
    Remapper remapper = new SimpleRemapper(oldClass, newClass);
    Label end = new Label();
    inlining = true;
    inlineTarget.instructions.resetLabels();
    JIMethodInliningAdapter mia = new JIMethodInliningAdapter(this, end,
            opcode == Opcodes.INVOKESTATIC ? Opcodes.ACC_STATIC : 0, desc,
            remapper);
    inlineTarget.accept(mia);
    inlining = false;
    super.visitLabel(end);
}
 
Example 7
Source File: TestLogImplementation.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void assertAllCharsOK() {
    char c = Character.MIN_VALUE;
    StringBuilder large = new StringBuilder();
    int logSize = 0;
    for(int i = Character.MIN_VALUE; i< (int)Character.MAX_VALUE; i++, c++) {
        large.append(c);
        logSize++;
        if (logSize == 80) {
            Logger.log(JFR_LOG_TAG, DEFAULT_TEST_LOG_LEVEL, large.toString());
            large = new StringBuilder();
        }
    }
}
 
Example 8
Source File: TestLogImplementation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void assertAllCharsOK() {
    char c = Character.MIN_VALUE;
    StringBuilder large = new StringBuilder();
    int logSize = 0;
    for(int i = Character.MIN_VALUE; i< (int)Character.MAX_VALUE; i++, c++) {
        large.append(c);
        logSize++;
        if (logSize == 80) {
            Logger.log(JFR_LOG_TAG, DEFAULT_TEST_LOG_LEVEL, large.toString());
            large = new StringBuilder();
        }
    }
}
 
Example 9
Source File: JDKEvents.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public synchronized static void initialize() {
    try {
        if (initializationTriggered == false) {
            for (Class<?> eventClass : eventClasses) {
                SecuritySupport.registerEvent((Class<? extends Event>) eventClass);
            }
            initializationTriggered = true;
            RequestEngine.addTrustedJDKHook(ExceptionStatisticsEvent.class, emitExceptionStatistics);
        }
    } catch (Exception e) {
        Logger.log(LogTag.JFR_SYSTEM, LogLevel.WARN, "Could not initialize JDK events. " + e.getMessage());
    }
}
 
Example 10
Source File: JDKEvents.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public synchronized static void initialize() {
    try {
        if (initializationTriggered == false) {
            for (Class<?> eventClass : eventClasses) {
                SecuritySupport.registerEvent((Class<? extends Event>) eventClass);
            }
            initializationTriggered = true;
            RequestEngine.addTrustedJDKHook(ExceptionStatisticsEvent.class, emitExceptionStatistics);
        }
    } catch (Exception e) {
        Logger.log(LogTag.JFR_SYSTEM, LogLevel.WARN, "Could not initialize JDK events. " + e.getMessage());
    }
}
 
Example 11
Source File: JIMethodMergeAdapter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if(methodInFilter(name, desc)) {
        // If the method is one that we will be replacing, delete the method
        Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.DEBUG, "Deleting " + name + desc);
        return null;
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
}
 
Example 12
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Flight Recorder for the platform.
 *
 * @return a Flight Recorder instance, not {@code null}
 *
 * @throws IllegalStateException if Flight Recorder can't be created (for
 *         example, if the Java Virtual Machine (JVM) lacks Flight Recorder
 *         support, or if the file repository can't be created or accessed)
 *
 * @throws SecurityException if a security manager exists and the caller does
 *         not have {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static FlightRecorder getFlightRecorder() throws IllegalStateException, SecurityException {
    synchronized (PlatformRecorder.class) {
        Utils.checkAccessFlightRecorder();
        JVMSupport.ensureWithIllegalStateException();
        if (platformRecorder == null) {
            try {
                platformRecorder = new FlightRecorder(new PlatformRecorder());
            } catch (IllegalStateException ise) {
                throw ise;
            } catch (Exception e) {
                throw new IllegalStateException("Can't create Flight Recorder. " + e.getMessage(), e);
            }
            // Must be in synchronized block to prevent instance leaking out
            // before initialization is done
            initialized = true;
            Logger.log(JFR, INFO, "Flight Recorder initialized");
            Logger.log(JFR, DEBUG, "maxchunksize: " + Options.getMaxChunkSize()+ " bytes");
            Logger.log(JFR, DEBUG, "memorysize: " + Options.getMemorySize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffersize: " + Options.getGlobalBufferSize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffercount: " + Options.getGlobalBufferCount());
            Logger.log(JFR, DEBUG, "dumppath: " + Options.getDumpPath());
            Logger.log(JFR, DEBUG, "samplethreads: " + Options.getSampleThreads());
            Logger.log(JFR, DEBUG, "stackdepth: " + Options.getStackDepth());
            Logger.log(JFR, DEBUG, "threadbuffersize: " + Options.getThreadBufferSize());
            Logger.log(JFR, LogLevel.INFO, "Created repository " + Repository.getRepository().getRepositoryPath().toString());
            PlatformRecorder.notifyRecorderInitialized(platformRecorder);
        }
    }
    return platformRecorder;
}
 
Example 13
Source File: ChunkHeader.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public MetadataDescriptor readMetadata() throws IOException {
    input.position(absoluteChunkStart + metadataPosition);
    input.readInt(); // size
    long id = input.readLong(); // event type id
    if (id != METADATA_TYPE_ID) {
        throw new IOException("Expected metadata event. Type id=" + id + ", should have been " + METADATA_TYPE_ID);
    }
    input.readLong(); // start time
    input.readLong(); // duration
    long metadataId = input.readLong();
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, "Metadata id=" + metadataId);
    // No need to read if metadataId == lastMetadataId, but we
    // do it for verification purposes.
    return MetadataDescriptor.read(input);
}
 
Example 14
Source File: JDKEvents.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public synchronized static void initialize() {
    try {
        if (initializationTriggered == false) {
            for (Class<?> eventClass : eventClasses) {
                SecuritySupport.registerEvent((Class<? extends Event>) eventClass);
            }
            initializationTriggered = true;
            FlightRecorder.addPeriodicEvent(ExceptionStatisticsEvent.class, emitExceptionStatistics);
        }
    } catch (Exception e) {
        Logger.log(LogTag.JFR_SYSTEM, LogLevel.WARN, "Could not initialize JDK events. " + e.getMessage());
    }
}
 
Example 15
Source File: ManagementSupport.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void logError(String message) {
    Logger.log(LogTag.JFR, LogLevel.ERROR, message);
}
 
Example 16
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();
}
 
Example 17
Source File: ChunkHeader.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private ChunkHeader(RecordingInput input, long absoluteChunkStart, long id) throws IOException {
    input.position(absoluteChunkStart);
    if (input.position() >= input.size()) {
        throw new IOException("Chunk contains no data");
    }
    verifyMagic(input);
    this.input = input;
    this.id = id;
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk " + id);
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: startPosition=" + absoluteChunkStart);
    major = input.readRawShort();
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: major=" + major);
    minor = input.readRawShort();
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: minor=" + minor);
    if (major != 1 && major != 2) {
        throw new IOException("File version " + major + "." + minor + ". Only Flight Recorder files of version 1.x and 2.x can be read by this JDK.");
    }
    chunkSize = input.readRawLong();
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: chunkSize=" + chunkSize);
    this.constantPoolPosition = input.readRawLong();
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: constantPoolPosition=" + constantPoolPosition);
    metadataPosition = input.readRawLong();
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: metadataPosition=" + metadataPosition);
    chunkStartNanos = input.readRawLong(); // nanos since epoch
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: startNanos=" + chunkStartNanos);
    durationNanos = input.readRawLong(); // duration nanos, not used
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: durationNanos=" + durationNanos);
    chunkStartTicks = input.readRawLong();
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: startTicks=" + chunkStartTicks);
    ticksPerSecond = input.readRawLong();
    Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: ticksPerSecond=" + ticksPerSecond);
    input.readRawInt(); // features, not used

    // set up boundaries
    this.absoluteChunkStart = absoluteChunkStart;
    absoluteChunkEnd = absoluteChunkStart + chunkSize;
    lastChunk = input.size() == absoluteChunkEnd;
    absoluteEventStart = input.position();

    // read metadata
    input.position(absoluteEventStart);
}
 
Example 18
Source File: TestLogImplementation.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void assertAllTagsForLevel(LogLevel level, String message) {
    for (LogTag tag : LogTag.values()) {
        Logger.log(tag, level, message);
    }
}
 
Example 19
Source File: TestLogImplementation.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void assertAllLevelsForTag(LogTag tag, String message) {
    for (LogLevel level : LogLevel.values()) {
        Logger.log(tag, level, message);
    }
}
 
Example 20
Source File: JIMethodCallInliner.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * inlineTarget defines the method to inline and also contains the actual
 * code to inline.
 *
 * @param access
 * @param desc
 * @param mv
 * @param inlineTarget
 * @param oldClass
 * @param newClass
 * @param logger
 */
public JIMethodCallInliner(int access, String desc, MethodVisitor mv,
        MethodNode inlineTarget, String oldClass, String newClass) {
    super(Opcodes.ASM5, access, desc, mv);
    this.oldClass = oldClass;
    this.newClass = newClass;
    this.inlineTarget = inlineTarget;

    Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.DEBUG, "MethodCallInliner: targetMethod=" + newClass + "."
            + inlineTarget.name + inlineTarget.desc);
}