jdk.jfr.consumer.RecordedObject Java Examples

The following examples show how to use jdk.jfr.consumer.RecordedObject. 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: JSONWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void printValueDescriptor(boolean first, boolean arrayElement, ValueDescriptor vd, Object value) {
    if (vd.isArray() && !arrayElement) {
        printNewDataStructure(first, arrayElement, vd.getName());
        if (!printIfNull(value)) {
            printArray(vd, (Object[]) value);
        }
        return;
    }
    if (!vd.getFields().isEmpty()) {
        printNewDataStructure(first, arrayElement, vd.getName());
        if (!printIfNull(value)) {
            printObject((RecordedObject) value);
        }
        return;
    }
    printValue(first, arrayElement, vd.getName(), value);
}
 
Example #2
Source File: XMLWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void printValueDescriptor(ValueDescriptor vd, Object value, int index) {
    boolean arrayElement = index != -1;
    String name = arrayElement ? null : vd.getName();
    if (vd.isArray() && !arrayElement) {
        if (printBeginElement("array", name, value, index)) {
            printArray(vd, (Object[]) value);
            printIndent();
            printEndElement("array");
        }
        return;
    }
    if (!vd.getFields().isEmpty()) {
        if (printBeginElement("struct", name, value, index)) {
            printObject((RecordedObject) value);
            printIndent();
            printEndElement("struct");
        }
        return;
    }
    if (printBeginElement("value", name, value, index)) {
        printEscaped(String.valueOf(value));
        printEndElement("value");
    }
}
 
Example #3
Source File: TestObjectDescription.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Set<String> extractObjectDescriptions(RecordedObject o) {
    Set<Long> visited = new HashSet<>();
    Set<String> descriptions = new HashSet<>();
    while (o != null) {
        Long memoryAddress = o.getValue("address");
        if (visited.contains(memoryAddress)) {
            return descriptions;
        }
        visited.add(memoryAddress);
        String od = o.getValue("description");
        if (od != null) {
            descriptions.add(od);
        }
        RecordedObject referrer = o.getValue("referrer");
        o = referrer != null ? referrer.getValue("object") : null;
    }
    return descriptions;
}
 
Example #4
Source File: Events.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static EventField assertField(RecordedEvent event, String name)  {
    String[] partNames = name.split("\\.");
    RecordedObject struct = event;
    try {
        for (int i=0; i<partNames.length; ++i) {
            final String partName =  partNames[i];
            final boolean isLastPart = i == partNames.length - 1;
            ValueDescriptor d = getValueDescriptor(struct, partName);
            if (isLastPart) {
                return new EventField(struct, d);
            } else {
                assertTrue(struct.getValue(partName) instanceof RecordedObject, "Expected '" + partName + "' to be a struct");
                struct = struct.getValue(partName);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.printf("Failed event:%n%s%n", event.toString());
    fail(String.format("Field %s not in event", name));
    return null;
}
 
Example #5
Source File: Events.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static EventField assertField(RecordedEvent event, String name)  {
    String[] partNames = name.split("\\.");
    RecordedObject struct = event;
    try {
        for (int i=0; i<partNames.length; ++i) {
            final String partName =  partNames[i];
            final boolean isLastPart = i == partNames.length - 1;
            ValueDescriptor d = getValueDescriptor(struct, partName);
            if (isLastPart) {
                return new EventField(struct, d);
            } else {
                assertTrue(struct.getValue(partName) instanceof RecordedObject, "Expected '" + partName + "' to be a struct");
                struct = struct.getValue(partName);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.printf("Failed event:%n%s%n", event.toString());
    fail(String.format("Field %s not in event", name));
    return null;
}
 
Example #6
Source File: InliningTest.java    From tlaplus with MIT License 6 votes vote down vote up
private boolean isNoMatch(RecordedObject methodNameMatch, Method method) {
		final String desc = methodNameMatch.getString("descriptor");
		final String[] params = desc.substring(1, desc.indexOf(")")).split(";");
		if (method.getParameterCount() == params.length) {
			Class<?>[] parameters = method.getParameterTypes();
			for (int j = 0; j < params.length; j++) {
				final String paramType = parameters[j].toString().replace(".", "/").replaceFirst("^(class|interface) ",
						"L");
				if (!params[j].equals(paramType)) {
					return true;
				}
			}
			System.out.println(methodNameMatch);
//			return false;
		}
		return true;
	}
 
Example #7
Source File: TestRecordedObject.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {

        RecordedObject event = makeRecordedObject();

        // Primitives
        testGetBoolean(event);
        testGetByte(event);
        testGetChar(event);
        testGetShort(event);
        testGetInt(event);
        testGetLong(event);
        testGetDouble(event);
        testGetFloat(event);

        // // Complex types
        testGetString(event);
        testGetInstant(event);
        testGetDuration(event);
        testGetThread(event);
        testGetClass(event);

        // Misc.
        testNestedNames(event);
        testTimeUnits(event);
        testUnsigned(event);
    }
 
Example #8
Source File: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void printOldObject(RecordedObject object) {
    println(" [");
    indent();
    printIndent();
    try {
        printReferenceChain(object);
    } catch (IllegalArgumentException iae) {
       // Could not find a field
       // Not possible to validate fields beforehand using RecordedObject#hasField
       // since nested objects, for example object.referrer.array.index, requires
       // an actual array object (which may be null).
    }
    retract();
    printIndent();
    println("]");
}
 
Example #9
Source File: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void printObject(RecordedObject object, long arraySize) {
    RecordedClass clazz = object.getClass("type");
    if (clazz != null) {
        String className = clazz.getName();
        if (className!= null && className.startsWith("[")) {
            className = decodeDescriptors(className, arraySize > 0 ? Long.toString(arraySize) : "").get(0);
        }
        print(className);
        String description = object.getString("description");
        if (description != null) {
            print(" ");
            print(description);
        }
    }
    println();
}
 
Example #10
Source File: TestRecordedObject.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void testGetThread(RecordedObject e) {
    RecordedThread thread = e.getValue("threadField");
    if (!thread.getJavaName().equals(THREAD_VALUE.getName())) {
        throw new AssertionError("Expected thread to have name " + THREAD_VALUE.getName());
    }
    assertGetter(x -> {
        // OK to access nullField if it is correct type
        // Chose a second null field with class type
        if ("nullField".equals(x)) {
            return e.getThread("nullField2");
        } else {
            return e.getThread(x);
        }

    }, thread, "thread");
}
 
Example #11
Source File: TestCompilerInlining.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testLevel(Map<Call, Boolean> expectedResult, int level) throws IOException {
    System.out.println("****** Testing level " + level + " *******");
    Recording r = new Recording();
    r.enable(EventNames.CompilerInlining);
    r.start();
    WHITE_BOX.enqueueMethodForCompilation(ENTRY_POINT, level);
    WHITE_BOX.deoptimizeMethod(ENTRY_POINT);
    r.stop();
    System.out.println("Expected:");

    List<RecordedEvent> events = Events.fromRecording(r);
    Set<Call> foundEvents = new HashSet<>();
    int foundRelevantEvent = 0;
    for (RecordedEvent event : events) {
        RecordedMethod callerObject = event.getValue("caller");
        RecordedObject calleeObject = event.getValue("callee");
        MethodDesc caller = methodToMethodDesc(callerObject);
        MethodDesc callee = ciMethodToMethodDesc(calleeObject);
        // only TestCase.* -> TestCase.* OR TestCase.* -> Object.<init> are tested/filtered
        if (caller.className.equals(TEST_CASE_CLASS_NAME) && (callee.className.equals(TEST_CASE_CLASS_NAME)
                || (callee.className.equals("java/lang/Object") && callee.methodName.equals("<init>")))) {
            System.out.println(event);
            boolean succeeded = (boolean) event.getValue("succeeded");
            int bci = Events.assertField(event, "bci").atLeast(0).getValue();
            Call call = new Call(caller, callee, bci);
            foundRelevantEvent++;
            Boolean expected = expectedResult.get(call);
            Asserts.assertNotNull(expected, "Unexpected inlined call : " + call);
            Asserts.assertEquals(expected, succeeded, "Incorrect result for " + call);
            Asserts.assertTrue(foundEvents.add(call), "repeated event for " + call);
        }
    }
    Asserts.assertEquals(foundRelevantEvent, expectedResult.size(), String.format("not all events found at lavel %d. " + "found = '%s'. expected = '%s'", level, events, expectedResult.keySet()));
    System.out.println();
    System.out.println();
}
 
Example #12
Source File: TestClassLoaderLeak.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        TestClassLoader testClassLoader = new TestClassLoader();
        for (Class<?> clazz : testClassLoader.loadClasses(OldObjects.MIN_SIZE / 20)) {
            // Allocate array to trigger sampling code path for interpreter / c1
            for (int i = 0; i < 20; i++) {
                Object classArray = Array.newInstance(clazz, 20);
                Array.set(classArray, i, clazz.newInstance());
                classObjects.add(classArray);
            }
        }
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        for (RecordedEvent e : events) {
            RecordedObject object = e.getValue("object");
            RecordedClass rc = object.getValue("type");
            if (rc.getName().contains("TestClass")) {
                return;
            }
        }
        Asserts.fail("Could not find class leak");
    }
}
 
Example #13
Source File: PrettyWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void printReferenceChain(RecordedObject object) {
    printObject(object, currentEvent.getLong("arrayElements"));
    for (RecordedObject ref = object.getValue("referrer"); ref != null; ref = object.getValue("referrer")) {
        long skip = ref.getLong("skip");
        if (skip > 0) {
            printIndent();
            println("...");
        }
        String objectHolder = "";
        long size = Long.MIN_VALUE;
        RecordedObject array = ref.getValue("array");
        if (array != null) {
            long index = array.getLong("index");
            size = array.getLong("size");
            objectHolder = "[" + index + "]";
        }
        RecordedObject field = ref.getValue("field");
        if (field != null) {
            objectHolder = field.getString("name");
        }
        printIndent();
        print(objectHolder);
        print(" : ");
        object = ref.getValue("object");
        if (object != null) {
            printObject(object, size);
        }
    }
}
 
Example #14
Source File: TestRecordedObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testTimeUnits(RecordedObject event) {
    Asserts.assertEquals(event.getDuration("durationMicros"), DURATION_VALUE);
    Asserts.assertEquals(event.getDuration("durationMillis"), DURATION_VALUE);
    Asserts.assertEquals(event.getDuration("durationSeconds"), DURATION_VALUE);
    Asserts.assertEquals(event.getInstant("instantMillis").toEpochMilli(), 1000L);
    if (!event.getInstant("instantTicks").isBefore(INSTANT_VALUE)) {
        throw new AssertionError("Expected start time of JVM to before call to Instant.now()");
    }
}
 
Example #15
Source File: TestArrayInformation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void verifyObjectArray(List<RecordedEvent> events) throws Exception {
    for (RecordedEvent e : events) {
        RecordedObject object = e.getValue("object");
        RecordedClass objectType = object.getValue("type");
        RecordedObject referrer = object.getValue("referrer");
        System.out.println(objectType.getName());
        if (objectType.getName().equals(ArrayLeak[].class.getName())) {
            for (int i = 0; i < CHAIN_DEPTH; i++) {
                object = referrer.getValue("object");
                if (object == null) {
                    throw new Exception("Expected referrer object");
                }
                objectType = object.getValue("type");
                if (!objectType.getName().equals(Object[].class.getName())) {
                    throw new Exception("Expect array class to be named " + Object[].class + " but found " + objectType.getName());
                }
                RecordedObject field = referrer.getValue("field");
                if (field != null) {
                    throw new Exception("Didn't expect to find field");
                }
                RecordedObject array = referrer.getValue("array");
                if (array == null) {
                    throw new Exception("Expected array object, but got null");
                }
                int index = referrer.getValue("array.index");
                if (index != ARRAY_INDEX) {
                    throw new Exception("Expected array index: " + ARRAY_INDEX + ", but got " + index);
                }
                int size = referrer.getValue("array.size");
                if (size != ARRAY_SIZE) {
                    throw new Exception("Expected array size: " + ARRAY_SIZE + ", but got " + size);
                }
                referrer = object.getValue("referrer");
            }
            return;
        }
    }
    throw new Exception("Could not find event with " + ArrayLeak[].class + " as (leak) object");
}
 
Example #16
Source File: TestFieldInformation.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasValidField(RecordedEvent e) throws Exception {
    RecordedObject object = e.getValue("object");
    Set<Long> visited = new HashSet<>();
    while (object != null) {
        Long address = object.getValue("address");
        if (visited.contains(address)) {
            return false;
        }
        visited.add(address);
        RecordedObject referrer = object.getValue("referrer");
        RecordedObject fieldObject = referrer != null ? referrer.getValue("field") : null;
        if (fieldObject != null) {
            String name = fieldObject.getValue("name");
            if (name != null && name.equals("testField")) {
                int modifiers = (short) fieldObject.getValue("modifiers");
                if (!Modifier.isStatic(modifiers)) {
                    throw new Exception("Field should be static");
                }
                if (!Modifier.isPublic(modifiers)) {
                    throw new Exception("Field should be private");
                }
                if (!Modifier.isFinal(modifiers)) {
                    throw new Exception("Field should be final");
                }
                if (Modifier.isTransient(modifiers)) {
                    throw new Exception("Field should not be transient");
                }
                if (Modifier.isVolatile(modifiers)) {
                    throw new Exception("Field should not be volatile");
                }
                return true;
            }
        }
        object = referrer != null ? referrer.getValue("object") : null;
    }
    return false;
}
 
Example #17
Source File: TestRecordedObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testUnsigned(RecordedObject event) {
    // Unsigned byte value
    Asserts.assertEquals(event.getByte("unsignedByte"), Byte.MIN_VALUE);
    Asserts.assertEquals(event.getInt("unsignedByte"), Byte.toUnsignedInt(Byte.MIN_VALUE));
    Asserts.assertEquals(event.getLong("unsignedByte"), Byte.toUnsignedLong(Byte.MIN_VALUE));
    Asserts.assertEquals(event.getShort("unsignedByte"), (short)Byte.toUnsignedInt(Byte.MIN_VALUE));

    // Unsigned char, nothing should happen, it is unsigned
    Asserts.assertEquals(event.getChar("unsignedChar"), 'q');
    Asserts.assertEquals(event.getInt("unsignedChar"), (int)'q');
    Asserts.assertEquals(event.getLong("unsignedChar"), (long)'q');

    // Unsigned short
    Asserts.assertEquals(event.getShort("unsignedShort"), Short.MIN_VALUE);
    Asserts.assertEquals(event.getInt("unsignedShort"), Short.toUnsignedInt(Short.MIN_VALUE));
    Asserts.assertEquals(event.getLong("unsignedShort"), Short.toUnsignedLong(Short.MIN_VALUE));

    // Unsigned int
    Asserts.assertEquals(event.getInt("unsignedInt"), Integer.MIN_VALUE);
    Asserts.assertEquals(event.getLong("unsignedInt"), Integer.toUnsignedLong(Integer.MIN_VALUE));

    // Unsigned long, nothing should happen
    Asserts.assertEquals(event.getLong("unsignedLong"), Long.MIN_VALUE);

    // Unsigned float, nothing should happen
    Asserts.assertEquals(event.getFloat("unsignedFloat"), Float.MIN_VALUE);

    // Unsigned double, nothing should happen
    Asserts.assertEquals(event.getDouble("unsignedDouble"), Double.MIN_VALUE);
}
 
Example #18
Source File: Events.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the recored name field
 *
 * @param ro should be a Package or a Module
 * @param targetName name to match
 */
private static boolean isMatchingTargetName(final RecordedObject ro, final String targetName) {
    if (ro == null) {
        return targetName == null;
    }

    final String recordedName = ro.getValue("name");

    if (recordedName == null) {
        return targetName == null;
    }

    return recordedName.equals(targetName);
}
 
Example #19
Source File: JSONWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void printObject(RecordedObject object) {
    printObjectBegin();
    boolean first = true;
    for (ValueDescriptor v : object.getFields()) {
        printValueDescriptor(first, false, v, object.getValue(v.getName()));
        first = false;
    }
    printObjectEnd();
}
 
Example #20
Source File: TestRecordedObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testUnsigned(RecordedObject event) {
    // Unsigned byte value
    Asserts.assertEquals(event.getByte("unsignedByte"), Byte.MIN_VALUE);
    Asserts.assertEquals(event.getInt("unsignedByte"), Byte.toUnsignedInt(Byte.MIN_VALUE));
    Asserts.assertEquals(event.getLong("unsignedByte"), Byte.toUnsignedLong(Byte.MIN_VALUE));
    Asserts.assertEquals(event.getShort("unsignedByte"), (short)Byte.toUnsignedInt(Byte.MIN_VALUE));

    // Unsigned char, nothing should happen, it is unsigned
    Asserts.assertEquals(event.getChar("unsignedChar"), 'q');
    Asserts.assertEquals(event.getInt("unsignedChar"), (int)'q');
    Asserts.assertEquals(event.getLong("unsignedChar"), (long)'q');

    // Unsigned short
    Asserts.assertEquals(event.getShort("unsignedShort"), Short.MIN_VALUE);
    Asserts.assertEquals(event.getInt("unsignedShort"), Short.toUnsignedInt(Short.MIN_VALUE));
    Asserts.assertEquals(event.getLong("unsignedShort"), Short.toUnsignedLong(Short.MIN_VALUE));

    // Unsigned int
    Asserts.assertEquals(event.getInt("unsignedInt"), Integer.MIN_VALUE);
    Asserts.assertEquals(event.getLong("unsignedInt"), Integer.toUnsignedLong(Integer.MIN_VALUE));

    // Unsigned long, nothing should happen
    Asserts.assertEquals(event.getLong("unsignedLong"), Long.MIN_VALUE);

    // Unsigned float, nothing should happen
    Asserts.assertEquals(event.getFloat("unsignedFloat"), Float.MIN_VALUE);

    // Unsigned double, nothing should happen
    Asserts.assertEquals(event.getDouble("unsignedDouble"), Double.MIN_VALUE);
}
 
Example #21
Source File: Events.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static ValueDescriptor getValueDescriptor(RecordedObject struct, String name) throws Exception {
    List<ValueDescriptor> valueDescriptors = struct.getFields();
    for (ValueDescriptor d : valueDescriptors) {
        if (name.equals(d.getName())) {
            return d;
        }
    }
    System.out.printf("Failed struct:%s", struct.toString());
    fail(String.format("Field %s not in struct", name));
    return null;
}
 
Example #22
Source File: Events.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void assertClassModule(final RecordedClass rc, final String moduleNameTarget) {
    final RecordedObject recordedPackage = getRecordedPackage(rc);
    final RecordedObject recordedModule = getRecordedModule(recordedPackage);

    if (recordedModule == null) {
        if (moduleNameTarget != null) {
            throw new RuntimeException("RecordedClass module is null!");
        }
        return;
    }

   assertTrue(isMatchingTargetName(recordedModule, moduleNameTarget), "mismatched module name! Target is " + moduleNameTarget);
}
 
Example #23
Source File: TestAllocationTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static RecordedObject findLeak(List<RecordedEvent> events, String name) throws Exception {
    for (RecordedEvent e : events) {
        if (e.getEventType().getName().equals(EventNames.OldObjectSample)) {
            RecordedObject object = e.getValue("object");
            RecordedClass rc = object.getValue("type");
            if (rc.getName().equals(Leak[].class.getName())) {
                return e;
            }
        }
    }
    return null;
}
 
Example #24
Source File: Events.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void assertClassPackage(final RecordedClass rc, final String packageNameTarget) {
    final RecordedObject recordedPackage = getRecordedPackage(rc);

    if (recordedPackage == null) {
        if (packageNameTarget != null) {
            throw new RuntimeException("RecordedClass package is null!");
        }
        return;
    }
    assertTrue(isMatchingTargetName(recordedPackage, packageNameTarget), "mismatched package name! Target is " + packageNameTarget);
}
 
Example #25
Source File: Events.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the recored name field
 *
 * @param ro should be a Package or a Module
 * @param targetName name to match
 */
private static boolean isMatchingTargetName(final RecordedObject ro, final String targetName) {
    if (ro == null) {
        return targetName == null;
    }

    final String recordedName = ro.getValue("name");

    if (recordedName == null) {
        return targetName == null;
    }

    return recordedName.equals(targetName);
}
 
Example #26
Source File: Events.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static ValueDescriptor getValueDescriptor(RecordedObject struct, String name) throws Exception {
    List<ValueDescriptor> valueDescriptors = struct.getFields();
    for (ValueDescriptor d : valueDescriptors) {
        if (name.equals(d.getName())) {
            return d;
        }
    }
    System.out.printf("Failed struct:%s", struct.toString());
    fail(String.format("Field %s not in struct", name));
    return null;
}
 
Example #27
Source File: Events.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void assertClassPackage(final RecordedClass rc, final String packageNameTarget) {
    final RecordedObject recordedPackage = getRecordedPackage(rc);

    if (recordedPackage == null) {
        if (packageNameTarget != null) {
            throw new RuntimeException("RecordedClass package is null!");
        }
        return;
    }
    assertTrue(isMatchingTargetName(recordedPackage, packageNameTarget), "mismatched package name! Target is " + packageNameTarget);
}
 
Example #28
Source File: Events.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static ValueDescriptor getValueDescriptor(RecordedObject struct, String name) throws Exception {
    List<ValueDescriptor> valueDescriptors = struct.getFields();
    for (ValueDescriptor d : valueDescriptors) {
        if (name.equals(d.getName())) {
            return d;
        }
    }
    System.out.printf("Failed struct:%s", struct.toString());
    fail(String.format("Field %s not in struct", name));
    return null;
}
 
Example #29
Source File: OldObjects.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static boolean matchingReferrerClass(RecordedEvent event, String className) {
    RecordedObject referrer = event.getValue("object.referrer");
    if (referrer != null) {
        if (!referrer.hasField("object.type")) {
            return false;
        }

        String reportedClass = ((RecordedClass) referrer.getValue("object.type")).getName();
        if (reportedClass.equals(className)) {
            return true;
        }
    }
    return false;
}
 
Example #30
Source File: OldObjects.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Predicate<RecordedEvent> isReferrerType(Class<?> referrerType) {
    if (referrerType != null) {
        return e -> {
            RecordedObject referrer = e.getValue("object.referrer");
            return referrer != null ? referrer.hasField("object.type") &&
                                        ((RecordedClass) referrer.getValue("object.type")).getName().equals(referrerType.getName()) : false;
        };
    } else {
        return e -> true;
    }
}