Skip to content
Permalink
Browse files

8199290: [TESTBUG] sun.hotspot.WhiteBox$WhiteBoxPermission is not copied

Reviewed-by: iignatyev, dholmes
  • Loading branch information
iklam committed Dec 16, 2019
1 parent 83163db commit 8b2453f93b064d36d589cedd8dd45ca4962e8979
Showing with 73 additions and 9 deletions.
  1. +31 −0 test/hotspot/jtreg/runtime/cds/appcds/JarBuilder.java
  2. +42 −9 test/lib/ClassFileInstaller.java
@@ -124,6 +124,35 @@ static void update(String jarFile, String dir) throws Exception {
executeProcess(args.toArray(new String[1]));
}

// Add commonly used inner classes that are often omitted by mistake. Currently
// we support only sun/hotspot/WhiteBox$WhiteBoxPermission. See JDK-8199290
private static String[] addInnerClasses(String[] classes, int startIdx) {
boolean seenWB = false;
boolean seenWBInner = false;
// This method is different than ClassFileInstaller.addInnerClasses which
// uses "." as the package delimiter :-(
final String wb = "sun/hotspot/WhiteBox";
final String wbInner = "sun/hotspot/WhiteBox$WhiteBoxPermission";

ArrayList<String> list = new ArrayList<>();

for (int i = startIdx; i < classes.length; i++) {
String cls = classes[i];
list.add(cls);
switch (cls) {
case wb: seenWB = true; break;
case wbInner: seenWBInner = true; break;
}
}
if (seenWB && !seenWBInner) {
list.add(wbInner);
}

String[] array = new String[list.size()];
list.toArray(array);
return array;
}


private static String createSimpleJar(String jarclassDir, String jarName,
String[] classNames) throws Exception {
@@ -140,6 +169,8 @@ private static String createSimpleJar(String jarclassDir, String jarName,
private static void addClassArgs(ArrayList<String> args, String jarclassDir,
String[] classNames) {

classNames = addInnerClasses(classNames, 0);

for (String name : classNames) {
args.add("-C");
args.add(jarclassDir);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2019, 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
@@ -32,6 +32,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

@@ -84,17 +85,47 @@ public static void main(String... args) throws Exception {
"where possible options include:\n" +
" -jar <path> Write to the JAR file <path>");
}
writeJar(args[1], null, args, 2, args.length);
String jarFile = args[1];
String[] classes = addInnerClasses(args, 2);
writeJar_impl(jarFile, null, classes);
} else {
if (DEBUG) {
System.out.println("ClassFileInstaller: Writing to " + System.getProperty("user.dir"));
}
for (String arg : args) {
writeClassToDisk(arg);
String[] classes = addInnerClasses(args, 0);
for (String cls : classes) {
writeClassToDisk(cls);
}
}
}

// Add commonly used inner classes that are often omitted by mistake. Currently
// we support only sun.hotspot.WhiteBox$WhiteBoxPermission. See JDK-8199290
private static String[] addInnerClasses(String[] classes, int startIdx) {
boolean seenWB = false;
boolean seenWBInner = false;
final String wb = "sun.hotspot.WhiteBox";
final String wbInner = "sun.hotspot.WhiteBox$WhiteBoxPermission";

ArrayList<String> list = new ArrayList<>();

for (int i = startIdx; i < classes.length; i++) {
String cls = classes[i];
list.add(cls);
switch (cls) {
case wb: seenWB = true; break;
case wbInner: seenWBInner = true; break;
}
}
if (seenWB && !seenWBInner) {
list.add(wbInner);
}

String[] array = new String[list.size()];
list.toArray(array);
return array;
}

public static class Manifest {
private InputStream in;

@@ -122,7 +153,7 @@ public InputStream getInputStream() {
}
}

private static void writeJar(String jarFile, Manifest manifest, String classes[], int from, int to) throws Exception {
private static void writeJar_impl(String jarFile, Manifest manifest, String classes[]) throws Exception {
if (DEBUG) {
System.out.println("ClassFileInstaller: Writing to " + getJarPath(jarFile));
}
@@ -137,8 +168,8 @@ private static void writeJar(String jarFile, Manifest manifest, String classes[]
writeToDisk(zos, "META-INF/MANIFEST.MF", manifest.getInputStream());
}

for (int i=from; i<to; i++) {
writeClassToDisk(zos, classes[i]);
for (String cls : classes) {
writeClassToDisk(zos, cls);
}

zos.close();
@@ -157,12 +188,14 @@ private static void writeJar(String jarFile, Manifest manifest, String classes[]
* @build ClassFileInstaller
*/
public static String writeJar(String jarFile, String... classes) throws Exception {
writeJar(jarFile, null, classes, 0, classes.length);
classes = addInnerClasses(classes, 0);
writeJar_impl(jarFile, null, classes);
return getJarPath(jarFile);
}

public static String writeJar(String jarFile, Manifest manifest, String... classes) throws Exception {
writeJar(jarFile, manifest, classes, 0, classes.length);
classes = addInnerClasses(classes, 0);
writeJar_impl(jarFile, manifest, classes);
return getJarPath(jarFile);
}

0 comments on commit 8b2453f

Please sign in to comment.
You can’t perform that action at this time.