Skip to content
Permalink
Browse files
8243451: nsk.share.jdi.Debugee.isJFR_active() is incorrect and corres…
…ponsing logic seems to be broken

Fix check isJFR_active()

Reviewed-by: sspitsyn, lmesnik
  • Loading branch information
Fairoz Matte committed Jun 11, 2020
1 parent 6a2e3ca commit b9ce3b435e76c561de92026bc352c47c99639103
Showing 4 changed files with 55 additions and 48 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -650,13 +650,4 @@ protected void killDebugee() {
}
}

public boolean isJFR_active() {
String opts = argumentHandler.getLaunchOptions();
int jfrPos = opts.indexOf("-XX:+FlightRecorder");

if (jfrPos >= 0)
return true;
else
return false;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@

import java.io.*;
import java.util.*;
import java.lang.reflect.Method;
import nsk.share.Log;
import nsk.share.ObjectInstancesManager;
import nsk.share.TestBug;
@@ -70,9 +71,13 @@ public class HeapwalkingDebuggee extends AbstractJDIDebuggee {
//create instance with all type referrers
static public final String COMMAND_CREATE_ALL_TYPE_REFERENCES = "createAllTypeReferences";

// check jfr is active process
public static boolean isJFRActive;

protected void init(String args[]) {
super.init(args);
objectInstancesManager = new ObjectInstancesManager(log);
isJFRActive = isJFRActive();
}

public void initDebuggee(DebugeeArgumentHandler argHandler, Log log, IOPipe pipe, String args[], boolean callExit) {
@@ -186,38 +191,15 @@ public boolean parseCommand(String command) {
return false;
}

// instances of some classes couldn't be strictly controlled during test execution, use non-strict checks for this classes
public static boolean useStrictCheck(String className, boolean otherThreadPresent) {
if (className.equals("java.lang.String"))
return false;

if (className.equals("char[]"))
return false;

if (className.equals("byte[]"))
return false;

if (className.equals("boolean[]"))
return false;

if (className.equals("float[]"))
return false;

if (className.equals("long[]"))
return false;

if (className.equals("int[]"))
return false;

if (className.equals("double[]"))
// check if jfr is initialized
public static boolean isJFRActive() {
try {
Class cls = Class.forName("jdk.jfr.FlightRecorder");
Method method = cls.getDeclaredMethod("isInitialized", new Class[0]);
return (Boolean)method.invoke(cls, new Object[0]);
} catch(Exception e) {
return false;

if (className.equals("java.lang.Thread")) {
if (otherThreadPresent)
return false;
}

return true;
}

// is reference with given type should be included in ObjectReference.referringObjects
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -33,8 +33,45 @@
public class HeapwalkingDebugger extends TestDebuggerType2 {
// instances of some classes couldn't be strictly controlled during test execution, use non-strict checks for this classes
protected boolean strictCheck(String className) {
boolean otherThreadPresent = isJFR_active();
return HeapwalkingDebuggee.useStrictCheck(className, otherThreadPresent);
if (className.equals("java.lang.String"))
return false;

if (className.equals("char[]"))
return false;

if (className.equals("byte[]"))
return false;

if (className.equals("boolean[]"))
return false;

if (className.equals("float[]"))
return false;

if (className.equals("long[]"))
return false;

if (className.equals("int[]"))
return false;

if (className.equals("double[]"))
return false;

if (className.equals("java.lang.Thread")) {
return !isJFRActive();
}

return true;
}

protected boolean isJFRActive() {
ReferenceType referenceType = debuggee.classByName("nsk.share.jdi.HeapwalkingDebuggee");
if (referenceType == null)
throw new RuntimeException("Debugeee is not initialized yet");

Field isJFRActiveFld = referenceType.fieldByName("isJFRActive");
boolean isJFRActive = ((BooleanValue)referenceType.getValue(isJFRActiveFld)).value();
return isJFRActive;
}

// wrapper for VirtualMachine.instanceCounts
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -357,7 +357,4 @@ protected void complain(String msg) {
log.complain("debugger FAILURE> " + msg + "\n");
}

protected boolean isJFR_active() {
return debuggee.isJFR_active();
}
}

0 comments on commit b9ce3b4

Please sign in to comment.