forked from openjdk/jdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update patch to new built-time approach
- Loading branch information
Showing
45 changed files
with
1,389 additions
and
799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
make/jdk/src/classes/build/tools/runtimelink/JimageDiffGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright (c) 2024, Red Hat, Inc. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package build.tools.runtimelink; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class JimageDiffGenerator { | ||
|
||
private static final boolean DEBUG = false; | ||
|
||
@SuppressWarnings("try") | ||
public interface ImageResource extends AutoCloseable { | ||
public List<String> getEntries(); | ||
public byte[] getResourceBytes(String name); | ||
} | ||
|
||
public List<ResourceDiff> generateDiff(ImageResource baseImg, ImageResource optImage) throws Exception { | ||
List<String> baseResources; | ||
Set<String> optResSet = new HashSet<>(); | ||
List<ResourceDiff> diffs = new ArrayList<>(); | ||
try (baseImg; | ||
optImage) { | ||
optResSet.addAll(optImage.getEntries()); | ||
baseResources = baseImg.getEntries(); | ||
for (String item: baseResources) { | ||
byte[] baseBytes = baseImg.getResourceBytes(item); | ||
// First check that every item in the base image exist in | ||
// the optimized image as well. If it does not, it's a removed | ||
// item in the optimized image. | ||
if (!optResSet.remove(item)) { | ||
// keep track of original bytes for removed item in the | ||
// optimized image, since we need to restore them for the | ||
// runtime image link | ||
ResourceDiff.Builder builder = new ResourceDiff.Builder(); | ||
ResourceDiff diff = builder.setKind(ResourceDiff.Kind.REMOVED) | ||
.setName(item) | ||
.setResourceBytes(baseBytes) | ||
.build(); | ||
diffs.add(diff); | ||
continue; | ||
} | ||
// Verify resource bytes are equal if present in both images | ||
boolean contentEquals = Arrays.equals(baseBytes, optImage.getResourceBytes(item)); | ||
if (!contentEquals) { | ||
// keep track of original bytes (non-optimized) | ||
ResourceDiff.Builder builder = new ResourceDiff.Builder(); | ||
ResourceDiff diff = builder.setKind(ResourceDiff.Kind.MODIFIED) | ||
.setName(item) | ||
.setResourceBytes(baseBytes) | ||
.build(); | ||
diffs.add(diff); | ||
} | ||
} | ||
} | ||
// What's now left in optResSet are the resources only present in the | ||
// optimized image (generated by some plugins; not present in jmods) | ||
for (String e: optResSet) { | ||
ResourceDiff.Builder builder = new ResourceDiff.Builder(); | ||
ResourceDiff diff = builder.setKind(ResourceDiff.Kind.ADDED) | ||
.setName(e) | ||
.build(); | ||
diffs.add(diff); | ||
} | ||
return diffs; | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
if (args.length != 3) { | ||
System.out.println("Usage: java -cp jrt-fs.jar:. JimageDiffGenerator <packaged-modules> <image-to-compare> <output-file>"); | ||
System.exit(1); | ||
} | ||
ImageResource base = new JmodsReader(Path.of(args[0])); | ||
ImageResource opt = new ImageReader(Path.of(args[1])); | ||
JimageDiffGenerator diffGen = new JimageDiffGenerator(); | ||
List<ResourceDiff> diffs = diffGen.generateDiff(base, opt); | ||
|
||
if (DEBUG) { | ||
printDiffs(diffs); | ||
} | ||
FileOutputStream fout = new FileOutputStream(new File(args[2])); | ||
ResourceDiff.write(diffs, fout); | ||
} | ||
|
||
private static void printDiffs(List<ResourceDiff> diffs) { | ||
for (ResourceDiff diff: diffs.stream().sorted().collect(Collectors.toList())) { | ||
switch (diff.getKind()) { | ||
case ADDED: | ||
System.out.println("Only added in opt: " + diff.getName()); | ||
break; | ||
case MODIFIED: | ||
System.out.println("Modified in opt: " + diff.getName()); | ||
break; | ||
case REMOVED: | ||
System.out.println("Removed in opt: " + diff.getName()); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.