Skip to content

Commit

Permalink
8065773: JDI: UOE is not thrown, when redefineClasses changes a class…
Browse files Browse the repository at this point in the history
… modifier

Reviewed-by: sspitsyn, coleenp
  • Loading branch information
lmesnik committed Jan 29, 2021
1 parent 739bbd0 commit f5ca838
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 671 deletions.
2 changes: 0 additions & 2 deletions test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded005
vmTestbase/nsk/monitoring/ThreadMXBean/ThreadInfo/Deadlock/JavaDeadlock001/TestDescription.java 8060733 generic-all

vmTestbase/nsk/jdi/ThreadReference/stop/stop001/TestDescription.java 7034630 generic-all
vmTestbase/nsk/jdi/VirtualMachine/redefineClasses/redefineclasses021/TestDescription.java 8065773 generic-all
vmTestbase/nsk/jdi/VirtualMachine/redefineClasses/redefineclasses023/TestDescription.java 8065773 generic-all

vmTestbase/nsk/jdb/eval/eval001/eval001.java 8221503 generic-all

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, 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
Expand Down Expand Up @@ -48,10 +48,8 @@
* <code>newclassXX/redefineclasses021a.java</code> - redefining debuggees <br>
*
* This test performs the following cases: <br>
* 1. newclass01 - adding <code>public</code> interface-modifier <br>
* 2. newclass02 - adding <code>protected</code> interface-modifier <br>
* 3. newclass03 - adding <code>private</code> interface-modifier <br>
* 4. newclass04 - adding <code>static</code> interface-modifier <br>
* 1. newclass01 - adding <code>public</code> interface-modifier <br>
* 2. newclass02 - removing <code>public</code> interface-modifier <br>
* The test checks two different cases for suspended debugee and not
* suspended one.
* When <code>canRedefineClasses()</code> is <code>false</code>, the test is
Expand All @@ -66,21 +64,23 @@ public class redefineclasses021 {
private final static String prefix = "nsk.jdi.VirtualMachine.redefineClasses.";
private final static String debuggerName = prefix + "redefineclasses021";
private final static String debugeeName = debuggerName + "a";
public final static String testedClassName = debuggerName + "b$redefineclasses021bi";

private final static String[][] subDirs = {
{"newclass01","adding <public> interface-modifier"},
{"newclass02","adding <protected> interface-modifier"},
{"newclass03","adding <private> interface-modifier"},
{"newclass04","adding <static> interface-modifier"}
{"newclass01","adding <public> interface-modifier", debuggerName + "b$redefineclasses021bi"},
{"newclass02","removing <public> interface-modifier", debuggerName + "b$redefineclasses021bir"},
};

private final static String newClassFile = File.separator
private final static String newClassFile(String testedClassName) {
return File.separator
+ testedClassName.replace('.',File.separatorChar)
+ ".class";
private final static String oldClassFile
= ClassFileFinder.findClassFile(testedClassName, Utils.TEST_CLASS_PATH)
}

private final static String oldClassFile(String testedClassName) {
return ClassFileFinder.findClassFile(testedClassName, Utils.TEST_CLASS_PATH)
.toString();
}

private static final String dashes = "--------------------------";

private static int exitStatus;
Expand All @@ -89,8 +89,6 @@ public class redefineclasses021 {
private static String testDir;
private static String statDebugee;

private ReferenceType testedClass;

private static void display(String msg) {
log.display(msg);
}
Expand Down Expand Up @@ -140,9 +138,6 @@ private void execTest() throws Failure {
return;
}

testedClass = debugee.classByName(testedClassName);
display(typePrompt(testedClass) + "\t:" + testedClass.name());

display("\nTEST BEGINS");
display("===========");

Expand All @@ -162,61 +157,43 @@ private void performCases() {
Map<? extends com.sun.jdi.ReferenceType,byte[]> mapBytes;
boolean alreadyComplained = false;
for (int i = 0; i < subDirs.length; i++) {

String testedClassName = subDirs[i][2];
ReferenceType testedClass = debugee.classByName(testedClassName);
display(typePrompt(testedClass) + "\t:" + testedClass.name());

display("\n" + subDirs[i][1] + ">>>");
mapBytes = mapClassToBytes(testDir + File.separator + subDirs [i][0] + newClassFile);
mapBytes = mapClassToBytes(testedClass, testDir + File.separator + subDirs [i][0] + newClassFile(testedClassName));
try {
debugee.VM().redefineClasses(mapBytes);
if (i < 3) {
if (!debugee.VM().canUnrestrictedlyRedefineClasses()) {
exitStatus = Consts.TEST_FAILED;
if (!alreadyComplained) {
alreadyComplained = true;
complain("***" + dashes);
complain("***" + statDebugee);
complain("***" + dashes);
}
complain("***UnsupportedOperationException is not thrown");
complain("***\twhile " + subDirs[i][1]);

display(">return to the previous state...");
mapBytes = mapClassToBytes(oldClassFile);
try {
debugee.VM().redefineClasses(mapBytes);
} catch (Exception e) {
throw new Failure(UNEXPECTED_STRING + e);
}
}
} else {
display("!!!No exception is thrown!!! Member interfaces are always implicitly static");
}
} catch (UnsupportedOperationException e) {
if (i == 3) {
complain(statDebugee + UNEXPECTED_STRING
+ "UnsupportedOperationException");
if (!debugee.VM().canUnrestrictedlyRedefineClasses()) {
exitStatus = Consts.TEST_FAILED;
} else {
if (!debugee.VM().canUnrestrictedlyRedefineClasses()) {
display(EXPECTED_STRING + e);
} else {
exitStatus = Consts.TEST_FAILED;
if (!alreadyComplained) {
alreadyComplained = true;
complain("***" + dashes);
complain("***" + statDebugee);
complain("***" + dashes);
}
complain(statDebugee + UNEXPECTED_STRING
+ "UnsupportedOperationException");
complain("***\twhile " + subDirs[i][1]);
if (!alreadyComplained) {
alreadyComplained = true;
complain("***" + dashes);
complain("***" + statDebugee);
complain("***" + dashes);
}
complain("***UnsupportedOperationException is not thrown");
complain("***\twhile " + subDirs[i][1]);

display(">return to the previous state...");
mapBytes = mapClassToBytes(testedClass, oldClassFile(testedClassName));
try {
debugee.VM().redefineClasses(mapBytes);
} catch (Exception e) {
throw new Failure(UNEXPECTED_STRING + e);
}
}
} catch (UnsupportedOperationException e) {
display(EXPECTED_STRING + e);
} catch (Exception e) {
throw new Failure(UNEXPECTED_STRING + e);
}
}
}

private Map<? extends com.sun.jdi.ReferenceType,byte[]> mapClassToBytes(String fileName) {
private Map<? extends com.sun.jdi.ReferenceType,byte[]> mapClassToBytes(ReferenceType testedClass, String fileName) {
display("class-file\t:" + fileName);
File fileToBeRedefined = new File(fileName);
int fileToRedefineLength = (int )fileToBeRedefined.length();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, 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
Expand Down Expand Up @@ -41,9 +41,7 @@
* newclassXX/redefineclasses021b.java - redefining debuggee's class
* This test performs the following cases:
* 1. newclass01 - adding <public> interface-modifier
* 2. newclass02 - adding <protected> interface-modifier
* 3. newclass03 - adding <private> interface-modifier
* 4. newclass04 - adding <static> interface-modifier
* 2. newclass02 - removing <public> interface-modifier
* The test checks two different cases for suspended debugee and not
* suspended one.
* COMMENTS:
Expand All @@ -57,9 +55,7 @@
*
* @comment compile newclassXX to bin/newclassXX
* with full debug info
* @run driver nsk.share.ExtraClassesBuilder
* -g:lines,source,vars
* newclass01 newclass02 newclass03 newclass04
* @run driver nsk.share.ExtraClassesBuilder -g:lines,source,vars newclass01 newclass02
*
* @run main/othervm
* nsk.jdi.VirtualMachine.redefineClasses.redefineclasses021
Expand All @@ -71,4 +67,3 @@
* -transport.address=dynamic
* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
*/

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, 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
Expand All @@ -23,10 +23,6 @@

package nsk.jdi.VirtualMachine.redefineClasses;

import nsk.share.*;
import nsk.share.jpda.*;
import nsk.share.jdi.*;

/**
* <code>redefineclasses021b</code> is deugee's part of the redefineclasses021.
* adding <code>public</code> modifier
Expand All @@ -42,7 +38,12 @@ public interface redefineclasses021bi {

}

class redefineclasses021bc implements redefineclasses021bi {
public interface redefineclasses021bir {
void dummyMethod01();

}

class redefineclasses021bc implements redefineclasses021bi, redefineclasses021bir {

public void dummyMethod01() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, 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
Expand Down Expand Up @@ -36,13 +36,18 @@ public class redefineclasses021b {

redefineclasses021bc obj = new redefineclasses021bc();

protected interface redefineclasses021bi {
// ^^^^^^^^^
interface redefineclasses021bi {
void dummyMethod01();

}

class redefineclasses021bc implements redefineclasses021bi {
/* public */ interface redefineclasses021bir {
//^^^^^^^^
void dummyMethod01();

}

class redefineclasses021bc implements redefineclasses021bi, redefineclasses021bir {

public void dummyMethod01() {
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, 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
Expand All @@ -23,10 +23,6 @@

package nsk.jdi.VirtualMachine.redefineClasses;

import nsk.share.*;
import nsk.share.jpda.*;
import nsk.share.jdi.*;

/**
* <code>redefineclasses021b</code> is deugee's part of the redefineclasses021.
*/
Expand All @@ -42,7 +38,14 @@ interface redefineclasses021bi {

}

class redefineclasses021bc implements redefineclasses021bi {
public interface redefineclasses021bir {


void dummyMethod01();

}

class redefineclasses021bc implements redefineclasses021bi, redefineclasses021bir {

public void dummyMethod01() {
}
Expand Down
Loading

0 comments on commit f5ca838

Please sign in to comment.