Date: Fri, 29 Apr 2016 14:50:50 -0700
Subject: [PATCH 019/228] 8149810: TIFFField#getAsLong throws
ClassCastException when data is type TIFFTag.TIFF_DOUBLE or TIFFTag.FLOAT
Expand the getAsLong() specification and handle the TIFF_DOUBLE and TIFF_FLOAT cases.
Reviewed-by: prr
---
.../javax/imageio/plugins/tiff/TIFFField.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFField.java b/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFField.java
index 336f81550b7..168e6b17328 100644
--- a/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFField.java
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFField.java
@@ -1089,6 +1089,15 @@ public class TIFFField implements Cloneable {
* {@code TIFF_SBYTE} data will be returned in the range
* [-128, 127].
*
+ * Data in {@code TIFF_FLOAT} and {@code TIFF_DOUBLE} are
+ * simply cast to {@code long} and may suffer from truncation.
+ *
+ *
Data in {@code TIFF_SRATIONAL} or
+ * {@code TIFF_RATIONAL} format are evaluated by dividing the
+ * numerator into the denominator using double-precision
+ * arithmetic and then casting to {@code long}. Loss of
+ * precision and truncation may occur.
+ *
*
Data in {@code TIFF_ASCII} format will be parsed as by
* the {@code Double.parseDouble} method, with the result
* cast to {@code long}.
@@ -1112,6 +1121,10 @@ public class TIFFField implements Cloneable {
case TIFFTag.TIFF_LONG:
case TIFFTag.TIFF_IFD_POINTER:
return ((long[])data)[index];
+ case TIFFTag.TIFF_FLOAT:
+ return (long)((float[])data)[index];
+ case TIFFTag.TIFF_DOUBLE:
+ return (long)((double[])data)[index];
case TIFFTag.TIFF_SRATIONAL:
int[] ivalue = getAsSRational(index);
return (long)((double)ivalue[0]/ivalue[1]);
From 5dda2fc113cd2a7c2c252f2726d200213f18bd8d Mon Sep 17 00:00:00 2001
From: Phil Race
Date: Fri, 29 Apr 2016 16:37:02 -0700
Subject: [PATCH 020/228] 8155772: gtk3_interface.c compilation error on Ubuntu
12.10
Reviewed-by: serb, kcr
---
.../java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c
index 6a188fb3598..060b082e53b 100644
--- a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c
+++ b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c
@@ -2547,14 +2547,14 @@ static jobject get_string_property(JNIEnv *env, GtkSettings* settings,
static jobject get_integer_property(JNIEnv *env, GtkSettings* settings,
const gchar* key) {
- gint intval = NULL;
+ gint intval = 0;
(*fp_g_object_get)(settings, key, &intval, NULL);
return create_Integer(env, intval);
}
static jobject get_boolean_property(JNIEnv *env, GtkSettings* settings,
const gchar* key) {
- gint intval = NULL;
+ gint intval = 0;
(*fp_g_object_get)(settings, key, &intval, NULL);
return create_Boolean(env, intval);
}
From 3dfed24a479db9972f0ba9324ca27a9586fe2a45 Mon Sep 17 00:00:00 2001
From: Max Ockner
Date: Fri, 29 Apr 2016 22:39:44 -0400
Subject: [PATCH 021/228] 8154110: Update class* and safepoint* logging
subsystems
Refactored logging tags in class and safepoint subsystems.
Reviewed-by: coleenp, rehn, hseigel
---
jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh | 2 +-
jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh | 2 +-
.../instrument/appendToClassLoaderSearch/ClassUnloadTest.sh | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh b/jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh
index 3872f813ffd..a00c14077d6 100644
--- a/jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh
+++ b/jdk/test/java/lang/ClassLoader/deadlock/TestCrossDelegate.sh
@@ -106,7 +106,7 @@ done
# run test
${TESTJAVA}${FS}bin${FS}java \
${TESTVMOPTS} \
- -verbose:class -Xlog:classload -cp . \
+ -verbose:class -Xlog:class+load -cp . \
-Dtest.classes=${TESTCLASSES} \
Starter cross
# -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass \
diff --git a/jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh b/jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh
index 198cd70827a..1289b4c861e 100644
--- a/jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh
+++ b/jdk/test/java/lang/ClassLoader/deadlock/TestOneWayDelegate.sh
@@ -102,7 +102,7 @@ done
# run test
${TESTJAVA}${FS}bin${FS}java \
${TESTVMOPTS} \
- -verbose:class -Xlog:classload -cp . \
+ -verbose:class -Xlog:class+load -cp . \
-Dtest.classes=${TESTCLASSES} \
Starter one-way
# -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass \
diff --git a/jdk/test/java/lang/instrument/appendToClassLoaderSearch/ClassUnloadTest.sh b/jdk/test/java/lang/instrument/appendToClassLoaderSearch/ClassUnloadTest.sh
index f5bb3b83179..b428a59bb28 100644
--- a/jdk/test/java/lang/instrument/appendToClassLoaderSearch/ClassUnloadTest.sh
+++ b/jdk/test/java/lang/instrument/appendToClassLoaderSearch/ClassUnloadTest.sh
@@ -80,5 +80,5 @@ $JAR ${TESTTOOLVMOPTS} -cfm "${TESTCLASSES}"/ClassUnloadTest.jar "${MANIFEST}" \
# Finally we run the test
(cd "${TESTCLASSES}"; \
- $JAVA ${TESTVMOPTS} -Xverify:none -Xlog:classunload \
+ $JAVA ${TESTVMOPTS} -Xverify:none -Xlog:class+unload \
-javaagent:ClassUnloadTest.jar ClassUnloadTest "${OTHERDIR}" Bar.jar)
From 1f092412dccc3eeb353c0ef4ab360a5999f2e050 Mon Sep 17 00:00:00 2001
From: Sergey Bylokhov
Date: Mon, 2 May 2016 12:01:39 +0300
Subject: [PATCH 022/228] 8154493: AppletViewer should emit its deprecation
warning to standard error
Reviewed-by: smarks
---
jdk/src/java.desktop/share/classes/sun/applet/Main.java | 3 ++-
.../DeprecatedAppletViewer/DeprecatedAppletViewer.java | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/jdk/src/java.desktop/share/classes/sun/applet/Main.java b/jdk/src/java.desktop/share/classes/sun/applet/Main.java
index 086b1113614..6c28c8f9d11 100644
--- a/jdk/src/java.desktop/share/classes/sun/applet/Main.java
+++ b/jdk/src/java.desktop/share/classes/sun/applet/Main.java
@@ -104,7 +104,8 @@ public class Main {
private int run(String [] args) {
// DECODE ARGS
try {
- System.out.println(lookup("deprecated"));
+ System.err.println(lookup("deprecated"));
+ System.err.flush();
if (args.length == 0) {
usage();
return 0;
diff --git a/jdk/test/sun/applet/DeprecatedAppletViewer/DeprecatedAppletViewer.java b/jdk/test/sun/applet/DeprecatedAppletViewer/DeprecatedAppletViewer.java
index f3b43f83eee..3c491011794 100644
--- a/jdk/test/sun/applet/DeprecatedAppletViewer/DeprecatedAppletViewer.java
+++ b/jdk/test/sun/applet/DeprecatedAppletViewer/DeprecatedAppletViewer.java
@@ -35,14 +35,14 @@ public final class DeprecatedAppletViewer {
private static final String TEXT = "AppletViewer is deprecated.";
public static void main(final String[] args) {
- final PrintStream old = System.out;
+ final PrintStream old = System.err;
final ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
final PrintStream ps = new PrintStream(baos);
try {
- System.setOut(ps);
+ System.setErr(ps);
sun.applet.Main.main(new String[]{});
} finally {
- System.setOut(old);
+ System.setErr(old);
}
final String text = new String(baos.toByteArray());
From 36865021a112e983a33d495d4a1ab0d4490ae2b0 Mon Sep 17 00:00:00 2001
From: Sergey Bylokhov
Date: Mon, 2 May 2016 12:08:59 +0300
Subject: [PATCH 023/228] 8027324: The spec for Toolkit.setDynamicLayout() and
Toolkit.isDynamicLayoutActive() needs to be clarified
Reviewed-by: alexsch, prr
---
.../share/classes/java/awt/Toolkit.java | 52 ++++++++++---------
.../awt/Toolkit/DynamicLayout/bug7172833.java | 22 +++++++-
2 files changed, 48 insertions(+), 26 deletions(-)
diff --git a/jdk/src/java.desktop/share/classes/java/awt/Toolkit.java b/jdk/src/java.desktop/share/classes/java/awt/Toolkit.java
index bed5149c08a..b45dd39a717 100644
--- a/jdk/src/java.desktop/share/classes/java/awt/Toolkit.java
+++ b/jdk/src/java.desktop/share/classes/java/awt/Toolkit.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2016, 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
@@ -207,30 +207,34 @@ public abstract class Toolkit {
}
/**
- * Returns whether dynamic layout of Containers on resize is
- * currently active (both set in program
- *( {@code isDynamicLayoutSet()} )
- *, and supported
- * by the underlying operating system and/or window manager).
- * If dynamic layout is currently inactive then Containers
- * re-layout their components when resizing is completed. As a result
- * the {@code Component.validate()} method will be invoked only
- * once per resize.
- * If dynamic layout is currently active then Containers
- * re-layout their components on every native resize event and
- * the {@code validate()} method will be invoked each time.
- * The OS/WM support can be queried using
- * the getDesktopProperty("awt.dynamicLayoutSupported") method.
+ * Returns whether dynamic layout of Containers on resize is currently
+ * enabled on the underlying operating system and/or window manager). If the
+ * platform supports it, {@code setDynamicLayout(boolean)} may be used to
+ * programmatically enable or disable platform dynamic layout. Regardless of
+ * whether that toggling is supported, or whether {@code true} or {@code
+ * false} is specified as an argument, or has never been called at all, this
+ * method will return the active current platform behavior and which will be
+ * followed by the JDK in determining layout policy during resizing.
+ *
+ * If dynamic layout is currently inactive then Containers re-layout their
+ * components when resizing is completed. As a result the
+ * {@code Component.validate()} method will be invoked only once per resize.
+ * If dynamic layout is currently active then Containers re-layout their
+ * components on every native resize event and the {@code validate()} method
+ * will be invoked each time. The OS/WM support can be queried using the
+ * getDesktopProperty("awt.dynamicLayoutSupported") method. This property
+ * will reflect the platform capability but is not sufficient to tell if it
+ * is presently enabled.
*
- * @return true if dynamic layout of Containers on resize is
- * currently active, false otherwise.
- * @exception HeadlessException if the GraphicsEnvironment.isHeadless()
- * method returns true
- * @see #setDynamicLayout(boolean dynamic)
- * @see #isDynamicLayoutSet()
- * @see #getDesktopProperty(String propertyName)
- * @see java.awt.GraphicsEnvironment#isHeadless
- * @since 1.4
+ * @return true if dynamic layout of Containers on resize is currently
+ * active, false otherwise.
+ * @throws HeadlessException if the GraphicsEnvironment.isHeadless() method
+ * returns true
+ * @see #setDynamicLayout(boolean dynamic)
+ * @see #isDynamicLayoutSet()
+ * @see #getDesktopProperty(String propertyName)
+ * @see java.awt.GraphicsEnvironment#isHeadless
+ * @since 1.4
*/
public boolean isDynamicLayoutActive()
throws HeadlessException {
diff --git a/jdk/test/java/awt/Toolkit/DynamicLayout/bug7172833.java b/jdk/test/java/awt/Toolkit/DynamicLayout/bug7172833.java
index 7c61804892b..2c4f04147b8 100644
--- a/jdk/test/java/awt/Toolkit/DynamicLayout/bug7172833.java
+++ b/jdk/test/java/awt/Toolkit/DynamicLayout/bug7172833.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015, 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
@@ -45,16 +45,34 @@ public final class bug7172833 {
public static void main(final String[] args) throws Exception {
final StubbedToolkit t = new StubbedToolkit();
-
+ final Boolean dynamicLayoutSupported
+ = (Boolean) t.getDesktopProperty("awt.dynamicLayoutSupported");
t.setDynamicLayout(true);
if(!t.isDynamicLayoutSet()){
throw new RuntimeException("'true' expected but 'false' returned");
}
+ if (dynamicLayoutSupported) {
+ if (!t.isDynamicLayoutActive()) {
+ throw new RuntimeException("is inactive but set+supported");
+ }
+ } else {
+ if (t.isDynamicLayoutActive()) {
+ throw new RuntimeException("is active but unsupported");
+ }
+ }
t.setDynamicLayout(false);
if(t.isDynamicLayoutSet()){
throw new RuntimeException("'false' expected but 'true' returned");
}
+ if (dynamicLayoutSupported) {
+ // Layout is supported and was set to false, cannot verifym because
+ // the native system is free to ignore our request.
+ } else {
+ if (t.isDynamicLayoutActive()) {
+ throw new RuntimeException("is active but unset+unsupported");
+ }
+ }
}
static final class StubbedToolkit extends Toolkit {
From 4ece44cbfaef95e46fc9357fd0823bcb4044bc41 Mon Sep 17 00:00:00 2001
From: Jamsheed Mohammed C M
Date: Tue, 10 May 2016 00:17:46 -0700
Subject: [PATCH 024/228] 8150016: small typo in ciReplay code
Changed atol to atoi
Reviewed-by: kvn
---
hotspot/src/share/vm/ci/ciReplay.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hotspot/src/share/vm/ci/ciReplay.cpp b/hotspot/src/share/vm/ci/ciReplay.cpp
index 8e3e6fb1ae3..27b00023563 100644
--- a/hotspot/src/share/vm/ci/ciReplay.cpp
+++ b/hotspot/src/share/vm/ci/ciReplay.cpp
@@ -823,7 +823,7 @@ class CompileReplay : public StackObj {
int value = atoi(string_value);
java_mirror->short_field_put(fd.offset(), value);
} else if (strcmp(field_signature, "Z") == 0) {
- int value = atol(string_value);
+ int value = atoi(string_value);
java_mirror->bool_field_put(fd.offset(), value);
} else if (strcmp(field_signature, "J") == 0) {
jlong value;
From 96c4dc32102ce810843e18243d52cd73d4a673c3 Mon Sep 17 00:00:00 2001
From: Jamsheed Mohammed C M
Date: Mon, 9 May 2016 23:49:22 -0700
Subject: [PATCH 025/228] 8144856: fix assert in
CompiledStaticCall::set_to_interpreted
Trivial cleanup in assert code.
Reviewed-by: kvn, goetz, thartmann
---
hotspot/src/cpu/aarch64/vm/compiledIC_aarch64.cpp | 6 ++++--
hotspot/src/cpu/ppc/vm/compiledIC_ppc.cpp | 9 +++++++--
hotspot/src/cpu/sparc/vm/compiledIC_sparc.cpp | 9 +++++++--
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/hotspot/src/cpu/aarch64/vm/compiledIC_aarch64.cpp b/hotspot/src/cpu/aarch64/vm/compiledIC_aarch64.cpp
index bd4e55a5151..1999b0f95be 100644
--- a/hotspot/src/cpu/aarch64/vm/compiledIC_aarch64.cpp
+++ b/hotspot/src/cpu/aarch64/vm/compiledIC_aarch64.cpp
@@ -92,9 +92,11 @@ void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry)
#ifndef PRODUCT
NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address());
- assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(),
+ // read the value once
+ volatile intptr_t data = method_holder->data();
+ assert(data == 0 || data == (intptr_t)callee(),
"a) MT-unsafe modification of inline cache");
- assert(method_holder->data() == 0 || jump->jump_destination() == entry,
+ assert(data == 0 || jump->jump_destination() == entry,
"b) MT-unsafe modification of inline cache");
#endif
// Update stub.
diff --git a/hotspot/src/cpu/ppc/vm/compiledIC_ppc.cpp b/hotspot/src/cpu/ppc/vm/compiledIC_ppc.cpp
index e50399de682..6ff77e028fe 100644
--- a/hotspot/src/cpu/ppc/vm/compiledIC_ppc.cpp
+++ b/hotspot/src/cpu/ppc/vm/compiledIC_ppc.cpp
@@ -178,10 +178,15 @@ void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry)
NativeMovConstReg* method_holder = nativeMovConstReg_at(stub + IC_pos_in_java_to_interp_stub);
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
- assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(),
+#ifdef ASSERT
+ // read the value once
+ volatile intptr_t data = method_holder->data();
+ volatile address destination = jump->jump_destination();
+ assert(data == 0 || data == (intptr_t)callee(),
"a) MT-unsafe modification of inline cache");
- assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry,
+ assert(destination == (address)-1 || destination == entry,
"b) MT-unsafe modification of inline cache");
+#endif
// Update stub.
method_holder->set_data((intptr_t)callee());
diff --git a/hotspot/src/cpu/sparc/vm/compiledIC_sparc.cpp b/hotspot/src/cpu/sparc/vm/compiledIC_sparc.cpp
index c544e7ae994..3536718fafc 100644
--- a/hotspot/src/cpu/sparc/vm/compiledIC_sparc.cpp
+++ b/hotspot/src/cpu/sparc/vm/compiledIC_sparc.cpp
@@ -101,10 +101,15 @@ void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry)
NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
- assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(),
+#ifdef ASSERT
+ // read the value once
+ intptr_t data = method_holder->data();
+ address destination = jump->jump_destination();
+ assert(data == 0 || data == (intptr_t)callee(),
"a) MT-unsafe modification of inline cache");
- assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry,
+ assert(destination == (address)-1 || destination == entry,
"b) MT-unsafe modification of inline cache");
+#endif
// Update stub.
method_holder->set_data((intptr_t)callee());
From 1e4b00b1dc91b1ac230771bce3b72c56ed1cea60 Mon Sep 17 00:00:00 2001
From: Goetz Lindenmaier
Date: Tue, 3 May 2016 12:23:06 +0200
Subject: [PATCH 026/228] 8140594: Various minor code improvements (compiler)
Various minor code improvements (compiler)
Reviewed-by: thartmann, kvn
---
hotspot/src/os/linux/vm/os_linux.cpp | 27 ++++++++++---------
.../src/os_cpu/linux_x86/vm/os_linux_x86.cpp | 2 +-
hotspot/src/share/vm/adlc/formssel.cpp | 13 ++++-----
hotspot/src/share/vm/c1/c1_LinearScan.cpp | 8 +++---
hotspot/src/share/vm/ci/ciMethodBlocks.cpp | 2 +-
.../share/vm/classfile/classFileParser.cpp | 11 +++++---
.../src/share/vm/classfile/classLoader.cpp | 7 ++---
.../share/vm/classfile/systemDictionary.cpp | 6 ++---
.../src/share/vm/compiler/compileBroker.cpp | 7 +++--
hotspot/src/share/vm/compiler/compileLog.cpp | 3 ++-
.../src/share/vm/compiler/disassembler.cpp | 6 ++---
hotspot/src/share/vm/logging/logTagSet.cpp | 10 +++++--
hotspot/src/share/vm/oops/constantPool.cpp | 3 ++-
hotspot/src/share/vm/oops/generateOopMap.cpp | 10 +++++--
hotspot/src/share/vm/opto/block.cpp | 2 +-
hotspot/src/share/vm/opto/callnode.cpp | 1 +
hotspot/src/share/vm/opto/graphKit.cpp | 2 +-
hotspot/src/share/vm/opto/matcher.cpp | 9 ++++---
hotspot/src/share/vm/runtime/relocator.cpp | 4 +--
19 files changed, 77 insertions(+), 56 deletions(-)
diff --git a/hotspot/src/os/linux/vm/os_linux.cpp b/hotspot/src/os/linux/vm/os_linux.cpp
index a9efaec274d..66b5718d73d 100644
--- a/hotspot/src/os/linux/vm/os_linux.cpp
+++ b/hotspot/src/os/linux/vm/os_linux.cpp
@@ -1913,9 +1913,10 @@ static bool _print_ascii_file(const char* filename, outputStream* st) {
return false;
}
- char buf[32];
+ char buf[33];
int bytes;
- while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) {
+ buf[32] = '\0';
+ while ((bytes = ::read(fd, buf, sizeof(buf)-1)) > 0) {
st->print_raw(buf, bytes);
}
@@ -6033,8 +6034,8 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
if (core_pattern[0] == '|') {
written = jio_snprintf(buffer, bufferSize,
- "\"%s\" (or dumping to %s/core.%d)",
- &core_pattern[1], p, current_process_id());
+ "\"%s\" (or dumping to %s/core.%d)",
+ &core_pattern[1], p, current_process_id());
} else {
written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern);
}
@@ -6067,20 +6068,20 @@ bool os::start_debugging(char *buf, int buflen) {
char *p = &buf[len];
jio_snprintf(p, buflen-len,
- "\n\n"
- "Do you want to debug the problem?\n\n"
- "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " UINTX_FORMAT " (" INTPTR_FORMAT ")\n"
- "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
- "Otherwise, press RETURN to abort...",
- os::current_process_id(), os::current_process_id(),
- os::current_thread_id(), os::current_thread_id());
+ "\n\n"
+ "Do you want to debug the problem?\n\n"
+ "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " UINTX_FORMAT " (" INTPTR_FORMAT ")\n"
+ "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
+ "Otherwise, press RETURN to abort...",
+ os::current_process_id(), os::current_process_id(),
+ os::current_thread_id(), os::current_thread_id());
bool yes = os::message_box("Unexpected Error", buf);
if (yes) {
// yes, user asked VM to launch debugger
- jio_snprintf(buf, sizeof(buf), "gdb /proc/%d/exe %d",
- os::current_process_id(), os::current_process_id());
+ jio_snprintf(buf, sizeof(char)*buflen, "gdb /proc/%d/exe %d",
+ os::current_process_id(), os::current_process_id());
os::fork_and_exec(buf);
yes = false;
diff --git a/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp b/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp
index 7d7aad54046..4b0b573ea25 100644
--- a/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp
+++ b/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp
@@ -823,7 +823,7 @@ void os::print_context(outputStream *st, const void *context) {
intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
- print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
+ print_hex_dump(st, (address)sp, (address)(sp + 8), sizeof(intptr_t));
st->cr();
// Note: it may be unsafe to inspect memory near pc. For example, pc may
diff --git a/hotspot/src/share/vm/adlc/formssel.cpp b/hotspot/src/share/vm/adlc/formssel.cpp
index a3faa48e426..aaef59a9441 100644
--- a/hotspot/src/share/vm/adlc/formssel.cpp
+++ b/hotspot/src/share/vm/adlc/formssel.cpp
@@ -1499,7 +1499,8 @@ void MachNodeForm::output(FILE *fp) {
// twice, we need to check that the operands are pointer-eequivalent in
// the DFA during the labeling process.
Predicate *InstructForm::build_predicate() {
- char buf[1024], *s=buf;
+ const int buflen = 1024;
+ char buf[buflen], *s=buf;
Dict names(cmpstr,hashstr,Form::arena); // Map Names to counts
MatchNode *mnode =
@@ -1508,12 +1509,12 @@ Predicate *InstructForm::build_predicate() {
uint first = 1;
// Start with the predicate supplied in the .ad file.
- if( _predicate ) {
- if( first ) first=0;
- strcpy(s,"("); s += strlen(s);
- strcpy(s,_predicate->_pred);
+ if (_predicate) {
+ if (first) first = 0;
+ strcpy(s, "("); s += strlen(s);
+ strncpy(s, _predicate->_pred, buflen - strlen(s) - 1);
s += strlen(s);
- strcpy(s,")"); s += strlen(s);
+ strcpy(s, ")"); s += strlen(s);
}
for( DictI i(&names); i.test(); ++i ) {
uintptr_t cnt = (uintptr_t)i._value;
diff --git a/hotspot/src/share/vm/c1/c1_LinearScan.cpp b/hotspot/src/share/vm/c1/c1_LinearScan.cpp
index 991daa0791b..dd45f5bf3b9 100644
--- a/hotspot/src/share/vm/c1/c1_LinearScan.cpp
+++ b/hotspot/src/share/vm/c1/c1_LinearScan.cpp
@@ -5521,7 +5521,8 @@ int LinearScanWalker::find_locked_double_reg(int reg_needed_until, int interval_
}
}
- if (_block_pos[max_reg] <= interval_to || _block_pos[max_reg + 1] <= interval_to) {
+ if (max_reg != any_reg &&
+ (_block_pos[max_reg] <= interval_to || _block_pos[max_reg + 1] <= interval_to)) {
*need_split = true;
}
@@ -6497,8 +6498,9 @@ void LinearScanStatistic::print(const char* title) {
if (_counters_sum[i] > 0 || _counters_max[i] >= 0) {
tty->print("%25s: %8d", counter_name(i), _counters_sum[i]);
- if (base_counter(i) != invalid_counter) {
- tty->print(" (%5.1f%%) ", _counters_sum[i] * 100.0 / _counters_sum[base_counter(i)]);
+ LinearScanStatistic::Counter cntr = base_counter(i);
+ if (cntr != invalid_counter) {
+ tty->print(" (%5.1f%%) ", _counters_sum[i] * 100.0 / _counters_sum[cntr]);
} else {
tty->print(" ");
}
diff --git a/hotspot/src/share/vm/ci/ciMethodBlocks.cpp b/hotspot/src/share/vm/ci/ciMethodBlocks.cpp
index 614e75dc3bf..3ce828ecb93 100644
--- a/hotspot/src/share/vm/ci/ciMethodBlocks.cpp
+++ b/hotspot/src/share/vm/ci/ciMethodBlocks.cpp
@@ -372,7 +372,7 @@ static const char *flagnames[] = {
void ciBlock::dump() {
tty->print(" [%d .. %d), {", _start_bci, _limit_bci);
- for (int i = 0; i < 8; i++) {
+ for (int i = 0; i < 7; i++) {
if ((_flags & (1 << i)) != 0) {
tty->print(" %s", flagnames[i]);
}
diff --git a/hotspot/src/share/vm/classfile/classFileParser.cpp b/hotspot/src/share/vm/classfile/classFileParser.cpp
index 81216bbd518..84d6673b860 100644
--- a/hotspot/src/share/vm/classfile/classFileParser.cpp
+++ b/hotspot/src/share/vm/classfile/classFileParser.cpp
@@ -1401,9 +1401,11 @@ class ClassFileParser::FieldAllocationCount : public ResourceObj {
FieldAllocationType update(bool is_static, BasicType type) {
FieldAllocationType atype = basic_type_to_atype(is_static, type);
- // Make sure there is no overflow with injected fields.
- assert(count[atype] < 0xFFFF, "More than 65535 fields");
- count[atype]++;
+ if (atype != BAD_ALLOCATION_TYPE) {
+ // Make sure there is no overflow with injected fields.
+ assert(count[atype] < 0xFFFF, "More than 65535 fields");
+ count[atype]++;
+ }
return atype;
}
};
@@ -3335,8 +3337,9 @@ void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cf
}
} else if (tag == vmSymbols::tag_bootstrap_methods() &&
_major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
- if (parsed_bootstrap_methods_attribute)
+ if (parsed_bootstrap_methods_attribute) {
classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK);
+ }
parsed_bootstrap_methods_attribute = true;
parse_classfile_bootstrap_methods_attribute(cfs, cp, attribute_length, CHECK);
} else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) {
diff --git a/hotspot/src/share/vm/classfile/classLoader.cpp b/hotspot/src/share/vm/classfile/classLoader.cpp
index 9fb99bc6bf0..cb5d8524e60 100644
--- a/hotspot/src/share/vm/classfile/classLoader.cpp
+++ b/hotspot/src/share/vm/classfile/classLoader.cpp
@@ -305,11 +305,9 @@ u1* ClassPathZipEntry::open_versioned_entry(const char* name, jint* filesize, TR
}
if (is_multi_ver) {
- int n;
char entry_name[JVM_MAXPATHLEN];
if (version > 0) {
- n = jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", version, name);
- entry_name[n] = '\0';
+ jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", version, name);
buffer = open_entry((const char*)entry_name, filesize, false, CHECK_NULL);
if (buffer == NULL) {
warning("Could not find %s in %s, try to find highest version instead", entry_name, _zip_name);
@@ -317,8 +315,7 @@ u1* ClassPathZipEntry::open_versioned_entry(const char* name, jint* filesize, TR
}
if (buffer == NULL) {
for (int i = cur_ver; i >= base_version; i--) {
- n = jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", i, name);
- entry_name[n] = '\0';
+ jio_snprintf(entry_name, sizeof(entry_name), "META-INF/versions/%d/%s", i, name);
buffer = open_entry((const char*)entry_name, filesize, false, CHECK_NULL);
if (buffer != NULL) {
break;
diff --git a/hotspot/src/share/vm/classfile/systemDictionary.cpp b/hotspot/src/share/vm/classfile/systemDictionary.cpp
index ede6d4f1df9..7dcd740f8a5 100644
--- a/hotspot/src/share/vm/classfile/systemDictionary.cpp
+++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp
@@ -1160,10 +1160,10 @@ Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
while ((index = strchr(name, '/')) != NULL) {
*index = '.'; // replace '/' with '.' in package name
}
- const char* fmt = "Prohibited package name: %s";
- size_t len = strlen(fmt) + strlen(name);
+ const char* msg_text = "Prohibited package name: ";
+ size_t len = strlen(msg_text) + strlen(name) + 1;
char* message = NEW_RESOURCE_ARRAY(char, len);
- jio_snprintf(message, len, fmt, name);
+ jio_snprintf(message, len, "%s%s", msg_text, name);
Exceptions::_throw_msg(THREAD_AND_LOCATION,
vmSymbols::java_lang_SecurityException(), message);
}
diff --git a/hotspot/src/share/vm/compiler/compileBroker.cpp b/hotspot/src/share/vm/compiler/compileBroker.cpp
index 22934de31aa..d49c0802729 100644
--- a/hotspot/src/share/vm/compiler/compileBroker.cpp
+++ b/hotspot/src/share/vm/compiler/compileBroker.cpp
@@ -2392,10 +2392,9 @@ void CompileBroker::print_times(bool per_compiler, bool aggregate) {
// Debugging output for failure
void CompileBroker::print_last_compile() {
- if ( _last_compile_level != CompLevel_none &&
- compiler(_last_compile_level) != NULL &&
- _last_method_compiled != NULL &&
- _last_compile_type != no_compile) {
+ if (_last_compile_level != CompLevel_none &&
+ compiler(_last_compile_level) != NULL &&
+ _last_compile_type != no_compile) {
if (_last_compile_type == osr_compile) {
tty->print_cr("Last parse: [osr]%d+++(%d) %s",
_osr_compilation_id, _last_compile_level, _last_method_compiled);
diff --git a/hotspot/src/share/vm/compiler/compileLog.cpp b/hotspot/src/share/vm/compiler/compileLog.cpp
index 6c0a87f9c91..638a2f2f96f 100644
--- a/hotspot/src/share/vm/compiler/compileLog.cpp
+++ b/hotspot/src/share/vm/compiler/compileLog.cpp
@@ -231,7 +231,8 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen)
// Copy any remaining data inside a quote:
bool saw_slop = false;
int end_cdata = 0; // state machine [0..2] watching for too many "]]"
- while ((nr = read(partial_fd, buf, buflen)) > 0) {
+ while ((nr = read(partial_fd, buf, buflen-1)) > 0) {
+ buf[buflen-1] = '\0';
if (!saw_slop) {
file->print_raw_cr("");
file->print_raw_cr("= 0) {
// 2. /jre/lib///hsdis-.so
strcpy(&buf[lib_offset], hsdis_library_name);
strcat(&buf[lib_offset], os::dll_file_extension());
_library = os::dll_load(buf, ebuf, sizeof ebuf);
}
- if (_library == NULL) {
+ if (_library == NULL && lib_offset > 0) {
// 3. /jre/lib//hsdis-.so
buf[lib_offset - 1] = '\0';
const char* p = strrchr(buf, *os::file_separator());
diff --git a/hotspot/src/share/vm/logging/logTagSet.cpp b/hotspot/src/share/vm/logging/logTagSet.cpp
index 96aae628857..6eb3cdb8158 100644
--- a/hotspot/src/share/vm/logging/logTagSet.cpp
+++ b/hotspot/src/share/vm/logging/logTagSet.cpp
@@ -104,12 +104,18 @@ void LogTagSet::vwrite(LogLevelType level, const char* fmt, va_list args) {
va_copy(saved_args, args);
size_t prefix_len = _write_prefix(buf, sizeof(buf));
// Check that string fits in buffer; resize buffer if necessary
- int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
+ int ret;
+ if (prefix_len < vwrite_buffer_size) {
+ ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
+ } else {
+ // Buffer too small. Just call printf to find out the length for realloc below.
+ ret = os::log_vsnprintf(buf, sizeof(buf), fmt, args);
+ }
assert(ret >= 0, "Log message buffer issue");
if ((size_t)ret >= sizeof(buf)) {
size_t newbuf_len = prefix_len + ret + 1;
char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
- memcpy(newbuf, buf, prefix_len);
+ prefix_len = _write_prefix(newbuf, newbuf_len);
ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args);
assert(ret >= 0, "Log message buffer issue");
log(level, newbuf);
diff --git a/hotspot/src/share/vm/oops/constantPool.cpp b/hotspot/src/share/vm/oops/constantPool.cpp
index ec22e2181c7..a291dc5d3f8 100644
--- a/hotspot/src/share/vm/oops/constantPool.cpp
+++ b/hotspot/src/share/vm/oops/constantPool.cpp
@@ -80,7 +80,8 @@ static bool tag_array_is_zero_initialized(Array* tags) {
ConstantPool::ConstantPool(Array* tags) :
_tags(tags),
- _length(tags->length()) {
+ _length(tags->length()),
+ _flags(0) {
assert(_tags != NULL, "invariant");
assert(tags->length() == _length, "invariant");
diff --git a/hotspot/src/share/vm/oops/generateOopMap.cpp b/hotspot/src/share/vm/oops/generateOopMap.cpp
index fe8cdbc64c6..6f44433af56 100644
--- a/hotspot/src/share/vm/oops/generateOopMap.cpp
+++ b/hotspot/src/share/vm/oops/generateOopMap.cpp
@@ -1678,8 +1678,14 @@ void GenerateOopMap::ppdupswap(int poplen, const char *out) {
CellTypeState actual[5];
assert(poplen < 5, "this must be less than length of actual vector");
- // pop all arguments
- for(int i = 0; i < poplen; i++) actual[i] = pop();
+ // Pop all arguments.
+ for (int i = 0; i < poplen; i++) {
+ actual[i] = pop();
+ }
+ // Field _state is uninitialized when calling push.
+ for (int i = poplen; i < 5; i++) {
+ actual[i] = CellTypeState::uninit;
+ }
// put them back
char push_ch = *out++;
diff --git a/hotspot/src/share/vm/opto/block.cpp b/hotspot/src/share/vm/opto/block.cpp
index bc3d772c3f8..ffa06e03358 100644
--- a/hotspot/src/share/vm/opto/block.cpp
+++ b/hotspot/src/share/vm/opto/block.cpp
@@ -1430,7 +1430,7 @@ void PhaseBlockLayout::find_edges() {
if (n->num_preds() != 1) break;
i++;
- assert(n = _cfg.get_block(i), "expecting next block");
+ assert(n == _cfg.get_block(i), "expecting next block");
tr->append(n);
uf->map(n->_pre_order, tr->id());
traces[n->_pre_order] = NULL;
diff --git a/hotspot/src/share/vm/opto/callnode.cpp b/hotspot/src/share/vm/opto/callnode.cpp
index 6a43b33cde4..66b2d086bbd 100644
--- a/hotspot/src/share/vm/opto/callnode.cpp
+++ b/hotspot/src/share/vm/opto/callnode.cpp
@@ -256,6 +256,7 @@ uint TailJumpNode::match_edge(uint idx) const {
JVMState::JVMState(ciMethod* method, JVMState* caller) :
_method(method) {
assert(method != NULL, "must be valid call site");
+ _bci = InvocationEntryBci;
_reexecute = Reexecute_Undefined;
debug_only(_bci = -99); // random garbage value
debug_only(_map = (SafePointNode*)-1);
diff --git a/hotspot/src/share/vm/opto/graphKit.cpp b/hotspot/src/share/vm/opto/graphKit.cpp
index 9350074955a..3a7d21ac897 100644
--- a/hotspot/src/share/vm/opto/graphKit.cpp
+++ b/hotspot/src/share/vm/opto/graphKit.cpp
@@ -1079,7 +1079,7 @@ bool GraphKit::compute_stack_effects(int& inputs, int& depth) {
case Bytecodes::_freturn:
case Bytecodes::_dreturn:
case Bytecodes::_areturn:
- assert(rsize = -depth, "");
+ assert(rsize == -depth, "");
inputs = rsize;
break;
diff --git a/hotspot/src/share/vm/opto/matcher.cpp b/hotspot/src/share/vm/opto/matcher.cpp
index 44127f3bc23..ed06b1e7459 100644
--- a/hotspot/src/share/vm/opto/matcher.cpp
+++ b/hotspot/src/share/vm/opto/matcher.cpp
@@ -659,11 +659,14 @@ void Matcher::Fixup_Save_On_Entry( ) {
uint reth_edge_cnt = TypeFunc::Parms+1;
RegMask *reth_rms = init_input_masks( reth_edge_cnt + soe_cnt, _return_addr_mask, c_frame_ptr_mask );
// Rethrow takes exception oop only, but in the argument 0 slot.
- reth_rms[TypeFunc::Parms] = mreg2regmask[find_receiver(false)];
+ OptoReg::Name reg = find_receiver(false);
+ if (reg >= 0) {
+ reth_rms[TypeFunc::Parms] = mreg2regmask[reg];
#ifdef _LP64
- // Need two slots for ptrs in 64-bit land
- reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(find_receiver(false)),1));
+ // Need two slots for ptrs in 64-bit land
+ reth_rms[TypeFunc::Parms].Insert(OptoReg::add(OptoReg::Name(reg), 1));
#endif
+ }
// Input RegMask array shared by all TailCalls
uint tail_call_edge_cnt = TypeFunc::Parms+2;
diff --git a/hotspot/src/share/vm/runtime/relocator.cpp b/hotspot/src/share/vm/runtime/relocator.cpp
index e6ad4d1bfc7..df1911f1360 100644
--- a/hotspot/src/share/vm/runtime/relocator.cpp
+++ b/hotspot/src/share/vm/runtime/relocator.cpp
@@ -612,8 +612,8 @@ bool Relocator::relocate_code(int bci, int ilen, int delta) {
// In case we have shrunken a tableswitch/lookupswitch statement, we store the last
// bytes that get overwritten. We have to copy the bytes after the change_jumps method
// has been called, since it is likely to update last offset in a tableswitch/lookupswitch
- if (delta < 0) {
- assert(delta>=-3, "we cannot overwrite more than 3 bytes");
+ assert(delta >= -3, "We cannot overwrite more than 3 bytes.");
+ if (delta < 0 && delta >= -3) {
memcpy(_overwrite, addr_at(bci + ilen + delta), -delta);
}
From 905d21fe7681109c9a5c959407be09aa4ae7fda6 Mon Sep 17 00:00:00 2001
From: Athijegannathan Sundararajan
Date: Mon, 16 May 2016 14:47:27 +0530
Subject: [PATCH 027/228] 8156914: jlink API minor cleanups
Reviewed-by: mchung
---
.../share/classes/jdk/tools/jlink/Jlink.java | 30 +-
.../jlink/builder/DefaultImageBuilder.java | 108 ++--
.../jdk/tools/jlink/builder/ImageBuilder.java | 6 +-
.../jlink/internal/ImageFileCreator.java | 55 +-
.../internal/ImagePluginConfiguration.java | 43 +-
.../jlink/internal/ImagePluginStack.java | 187 ++++---
.../tools/jlink/internal/ModuleEntryImpl.java | 164 ++++++
.../tools/jlink/internal/ModulePoolImpl.java | 421 ++++++++++++++
.../jlink/internal/PluginContextImpl.java | 37 --
.../jdk/tools/jlink/internal/PoolImpl.java | 167 ------
.../jlink/internal/ResourcePrevisitor.java | 4 +-
.../jdk/tools/jlink/internal/TaskHelper.java | 9 +-
.../jdk/tools/jlink/internal/Utils.java | 48 +-
.../packager/AppRuntimeImageBuilder.java | 2 +-
.../plugins/DefaultCompressPlugin.java | 21 +-
.../internal/plugins/ExcludeFilesPlugin.java | 16 +-
.../jlink/internal/plugins/ExcludePlugin.java | 15 +-
.../internal/plugins/ExcludeVMPlugin.java | 31 +-
.../internal/plugins/FileCopierPlugin.java | 34 +-
.../plugins/GenerateJLIClassesPlugin.java | 23 +-
.../plugins/IncludeLocalesPlugin.java | 29 +-
.../internal/plugins/OptimizationPlugin.java | 7 +-
.../plugins/OrderResourcesPlugin.java | 29 +-
.../internal/plugins/ReleaseInfoPlugin.java | 103 ++--
.../internal/plugins/StringSharingPlugin.java | 36 +-
.../internal/plugins/StripDebugPlugin.java | 22 +-
.../plugins/StripNativeCommandsPlugin.java | 16 +-
.../plugins/SystemModuleDescriptorPlugin.java | 39 +-
.../jlink/internal/plugins/ZipPlugin.java | 25 +-
.../jlink/internal/plugins/asm/AsmPlugin.java | 16 +-
.../jlink/internal/plugins/asm/AsmPool.java | 25 +-
.../internal/plugins/asm/AsmPoolImpl.java | 93 ++-
.../jlink/internal/plugins/asm/AsmPools.java | 72 +--
.../tools/jlink/plugin/ExecutableImage.java | 39 +-
.../jdk/tools/jlink/plugin/LinkModule.java | 87 +++
.../jdk/tools/jlink/plugin/ModuleEntry.java | 155 +++++
.../jdk/tools/jlink/plugin/ModulePool.java | 136 +++++
.../jdk/tools/jlink/plugin/Plugin.java | 40 +-
.../jdk/tools/jlink/plugin/PluginContext.java | 37 --
.../classes/jdk/tools/jlink/plugin/Pool.java | 528 ------------------
.../tools/jlink/plugin/TransformerPlugin.java | 2 +-
.../jdk.jlink/share/classes/module-info.java | 4 +-
jdk/test/tools/jlink/DefaultProviderTest.java | 18 +-
.../tools/jlink/ImageFileCreatorTest.java | 5 +-
jdk/test/tools/jlink/ImageFilePoolTest.java | 59 +-
jdk/test/tools/jlink/IntegrationTest.java | 20 +-
jdk/test/tools/jlink/JLinkOptimTest.java | 30 +-
jdk/test/tools/jlink/JLinkOptionsTest.java | 4 +-
.../tools/jlink/JLinkPostProcessingTest.java | 6 +-
jdk/test/tools/jlink/ResourcePoolTest.java | 122 ++--
jdk/test/tools/jlink/SecurityTest.java | 1 +
.../asmplugin/AddForgetResourcesTest.java | 84 +--
.../jlink/asmplugin/AsmPluginTestBase.java | 36 +-
jdk/test/tools/jlink/asmplugin/BasicTest.java | 16 +-
.../jlink/asmplugin/IdentityPluginTest.java | 25 +-
.../tools/jlink/asmplugin/NegativeTest.java | 8 +-
.../jlink/asmplugin/PackageMappingTest.java | 12 +-
.../tools/jlink/asmplugin/SortingTest.java | 42 +-
.../tools/jlink/asmplugin/VisitorTest.java | 22 +-
.../customplugin/plugin/CustomPlugin.java | 19 +-
.../customplugin/plugin/HelloPlugin.java | 16 +-
.../jlink/plugins/CompressorPluginTest.java | 82 +--
.../jlink/plugins/ExcludeFilesPluginTest.java | 19 +-
.../jlink/plugins/ExcludePluginTest.java | 16 +-
.../jlink/plugins/ExcludeVMPluginTest.java | 37 +-
.../jlink/plugins/FileCopierPluginTest.java | 21 +-
.../tools/jlink/plugins/LastSorterTest.java | 53 +-
.../plugins/OrderResourcesPluginTest.java | 79 +--
.../tools/jlink/plugins/PluginOrderTest.java | 58 +-
.../jlink/plugins/PluginsNegativeTest.java | 22 +-
.../tools/jlink/plugins/PrevisitorTest.java | 49 +-
.../plugins/StringSharingPluginTest.java | 26 +-
.../jlink/plugins/StripDebugPluginTest.java | 20 +-
73 files changed, 2077 insertions(+), 1911 deletions(-)
create mode 100644 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ModuleEntryImpl.java
create mode 100644 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ModulePoolImpl.java
delete mode 100644 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginContextImpl.java
delete mode 100644 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PoolImpl.java
create mode 100644 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/LinkModule.java
create mode 100644 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/ModuleEntry.java
create mode 100644 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/ModulePool.java
delete mode 100644 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/PluginContext.java
delete mode 100644 jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/Pool.java
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/Jlink.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/Jlink.java
index 92d7eb64fcf..e899d378963 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/Jlink.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/Jlink.java
@@ -34,11 +34,9 @@ import java.util.Objects;
import java.util.Set;
import jdk.tools.jlink.internal.JlinkTask;
import jdk.tools.jlink.plugin.Plugin;
-import jdk.tools.jlink.plugin.PluginContext;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.builder.ImageBuilder;
-import jdk.tools.jlink.internal.PluginContextImpl;
import jdk.tools.jlink.internal.PluginRepository;
/**
@@ -71,7 +69,6 @@ public final class Jlink {
private final List plugins;
private final ImageBuilder imageBuilder;
private final String lastSorterPluginName;
- private final PluginContext pluginContext;
/**
* Empty plugins configuration.
@@ -86,7 +83,7 @@ public final class Jlink {
* @param plugins List of plugins.
*/
public PluginsConfiguration(List plugins) {
- this(plugins, null, null, null);
+ this(plugins, null, null);
}
/**
@@ -101,28 +98,10 @@ public final class Jlink {
*/
public PluginsConfiguration(List plugins,
ImageBuilder imageBuilder, String lastSorterPluginName) {
- this(plugins, imageBuilder, lastSorterPluginName, null);
- }
-
- /**
- * Plugins configuration with a last sorter and an ImageBuilder. No
- * sorting can occur after the last sorter plugin. The ImageBuilder is
- * in charge to layout the image content on disk.
- *
- * @param plugins List of transformer plugins.
- * @param imageBuilder Image builder.
- * @param lastSorterPluginName Name of last sorter plugin, no sorting
- * @param ctx the plugin context
- * can occur after it.
- */
- public PluginsConfiguration(List plugins,
- ImageBuilder imageBuilder, String lastSorterPluginName,
- PluginContext ctx) {
this.plugins = plugins == null ? Collections.emptyList()
: plugins;
this.imageBuilder = imageBuilder;
this.lastSorterPluginName = lastSorterPluginName;
- this.pluginContext = ctx != null? ctx : new PluginContextImpl();
}
/**
@@ -146,13 +125,6 @@ public final class Jlink {
return lastSorterPluginName;
}
- /**
- * @return the pluginContext
- */
- public PluginContext getPluginContext() {
- return pluginContext;
- }
-
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java
index a3943145c06..2c0620a99db 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java
@@ -1,3 +1,4 @@
+
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -24,8 +25,6 @@
*/
package jdk.tools.jlink.builder;
-import jdk.tools.jlink.plugin.ExecutableImage;
-import jdk.tools.jlink.plugin.PluginException;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
@@ -47,8 +46,10 @@ import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
@@ -56,23 +57,40 @@ import java.util.Set;
import jdk.tools.jlink.internal.BasicImageWriter;
import jdk.tools.jlink.internal.plugins.FileCopierPlugin;
import jdk.tools.jlink.internal.plugins.FileCopierPlugin.SymImageFile;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.Module;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
+import jdk.tools.jlink.plugin.ExecutableImage;
+import jdk.tools.jlink.plugin.ModulePool;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.PluginException;
/**
*
* Default Image Builder. This builder creates the default runtime image layout.
*/
-public class DefaultImageBuilder implements ImageBuilder {
+public final class DefaultImageBuilder implements ImageBuilder {
/**
* The default java executable Image.
*/
- static class DefaultExecutableImage extends ExecutableImage {
+ static final class DefaultExecutableImage implements ExecutableImage {
+
+ private final Path home;
+ private final List args;
+ private final Set modules;
public DefaultExecutableImage(Path home, Set modules) {
- super(home, modules, createArgs(home));
+ this(home, modules, createArgs(home));
+ }
+
+ private DefaultExecutableImage(Path home, Set modules,
+ List args) {
+ Objects.requireNonNull(home);
+ Objects.requireNonNull(args);
+ if (!Files.exists(home)) {
+ throw new IllegalArgumentException("Invalid image home");
+ }
+ this.home = home;
+ this.modules = Collections.unmodifiableSet(modules);
+ this.args = Collections.unmodifiableList(args);
}
private static List createArgs(Path home) {
@@ -83,6 +101,21 @@ public class DefaultImageBuilder implements ImageBuilder {
return javaArgs;
}
+ @Override
+ public Path getHome() {
+ return home;
+ }
+
+ @Override
+ public Set getModules() {
+ return modules;
+ }
+
+ @Override
+ public List getExecutionArgs() {
+ return args;
+ }
+
@Override
public void storeLaunchArgs(List args) {
try {
@@ -111,17 +144,19 @@ public class DefaultImageBuilder implements ImageBuilder {
Files.createDirectories(mdir);
}
- private void storeFiles(Set modules, Properties release) throws IOException {
+ private void storeFiles(Set modules, Map release) throws IOException {
if (release != null) {
- addModules(release, modules);
+ Properties props = new Properties();
+ props.putAll(release);
+ addModules(props, modules);
File r = new File(root.toFile(), "release");
try (FileOutputStream fo = new FileOutputStream(r)) {
- release.store(fo, null);
+ props.store(fo, null);
}
}
}
- private void addModules(Properties release, Set modules) throws IOException {
+ private void addModules(Properties props, Set modules) throws IOException {
StringBuilder builder = new StringBuilder();
int i = 0;
for (String m : modules) {
@@ -131,28 +166,32 @@ public class DefaultImageBuilder implements ImageBuilder {
}
i++;
}
- release.setProperty("MODULES", builder.toString());
+ props.setProperty("MODULES", builder.toString());
}
@Override
- public void storeFiles(Pool files, Properties release) {
+ public void storeFiles(ModulePool files) {
try {
- for (ModuleData f : files.getContent()) {
- if (!f.getType().equals(Pool.ModuleDataType.CLASS_OR_RESOURCE)) {
- accept(f);
+ files.entries().forEach(f -> {
+ if (!f.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
+ try {
+ accept(f);
+ } catch (IOException ioExp) {
+ throw new UncheckedIOException(ioExp);
+ }
}
- }
- for (Module m : files.getModules()) {
+ });
+ files.modules().forEach(m -> {
// Only add modules that contain packages
if (!m.getAllPackages().isEmpty()) {
// Skip the fake module used by FileCopierPlugin when copying files.
if (m.getName().equals(FileCopierPlugin.FAKE_MODULE)) {
- continue;
+ return;
}
modules.add(m.getName());
}
- }
- storeFiles(modules, release);
+ });
+ storeFiles(modules, files.getReleaseProperties());
if (Files.getFileStore(root).supportsFileAttributeView(PosixFileAttributeView.class)) {
// launchers in the bin directory need execute permission
@@ -168,8 +207,8 @@ public class DefaultImageBuilder implements ImageBuilder {
Path lib = root.resolve("lib");
if (Files.isDirectory(lib)) {
Files.find(lib, 2, (path, attrs) -> {
- return path.getFileName().toString().equals("jspawnhelper") ||
- path.getFileName().toString().equals("jexec");
+ return path.getFileName().toString().equals("jspawnhelper")
+ || path.getFileName().toString().equals("jexec");
}).forEach(this::setExecutable);
}
}
@@ -180,27 +219,23 @@ public class DefaultImageBuilder implements ImageBuilder {
}
}
- @Override
- public void storeFiles(Pool files) {
- storeFiles(files, new Properties());
- }
-
/**
* Generates launcher scripts.
+ *
* @param imageContent The image content.
* @param modules The set of modules that the runtime image contains.
* @throws IOException
*/
- protected void prepareApplicationFiles(Pool imageContent, Set modules) throws IOException {
+ protected void prepareApplicationFiles(ModulePool imageContent, Set modules) throws IOException {
// generate launch scripts for the modules with a main class
for (String module : modules) {
String path = "/" + module + "/module-info.class";
- ModuleData res = imageContent.get(path);
- if (res == null) {
+ Optional res = imageContent.findEntry(path);
+ if (!res.isPresent()) {
throw new IOException("module-info.class not found for " + module + " module");
}
Optional mainClass;
- ByteArrayInputStream stream = new ByteArrayInputStream(res.getBytes());
+ ByteArrayInputStream stream = new ByteArrayInputStream(res.get().getBytes());
mainClass = ModuleDescriptor.read(stream).mainClass();
if (mainClass.isPresent()) {
Path cmd = root.resolve("bin").resolve(module);
@@ -263,9 +298,9 @@ public class DefaultImageBuilder implements ImageBuilder {
}
}
- private void accept(ModuleData file) throws IOException {
+ private void accept(ModuleEntry file) throws IOException {
String fullPath = file.getPath();
- String module = "/" + file.getModule()+ "/";
+ String module = "/" + file.getModule() + "/";
String filename = fullPath.substring(module.length());
// Remove radical native|config|...
filename = filename.substring(filename.indexOf('/') + 1);
@@ -404,8 +439,7 @@ public class DefaultImageBuilder implements ImageBuilder {
public static ExecutableImage getExecutableImage(Path root) {
if (Files.exists(root.resolve("bin").resolve(getJavaProcessName()))) {
- return new DefaultImageBuilder.DefaultExecutableImage(root,
- retrieveModules(root));
+ return new DefaultExecutableImage(root, retrieveModules(root));
}
return null;
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/ImageBuilder.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/ImageBuilder.java
index dc0bf71c535..10cea85d363 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/ImageBuilder.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/ImageBuilder.java
@@ -29,7 +29,7 @@ import java.util.Properties;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
+import jdk.tools.jlink.plugin.ModulePool;
/**
* Implement this interface to develop your own image layout. First the jimage
@@ -45,7 +45,7 @@ public interface ImageBuilder {
* @param release the release properties
* @throws PluginException
*/
- public default void storeFiles(Pool content, Properties release) {
+ public default void storeFiles(ModulePool content, Properties release) {
storeFiles(content);
}
@@ -55,7 +55,7 @@ public interface ImageBuilder {
* @param content Pool of module content.
* @throws PluginException
*/
- public default void storeFiles(Pool content) {
+ public default void storeFiles(ModulePool content) {
throw new UnsupportedOperationException("storeFiles");
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
index e0347e52a21..f765be2919b 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
@@ -44,12 +44,11 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import jdk.tools.jlink.internal.Archive.Entry;
import jdk.tools.jlink.internal.Archive.Entry.EntryType;
-import jdk.tools.jlink.internal.PoolImpl.CompressedModuleData;
+import jdk.tools.jlink.internal.ModulePoolImpl.CompressedModuleData;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
-import jdk.tools.jlink.plugin.Pool.ModuleDataType;
+import jdk.tools.jlink.plugin.ModulePool;
+import jdk.tools.jlink.plugin.ModuleEntry;
/**
* An image (native endian.)
@@ -145,7 +144,7 @@ public final class ImageFileCreator {
}));
ByteOrder order = ByteOrder.nativeOrder();
BasicImageWriter writer = new BasicImageWriter(order);
- PoolImpl pool = createPools(archives, entriesForModule, order, writer);
+ ModulePoolImpl pool = createPools(archives, entriesForModule, order, writer);
try (OutputStream fos = Files.newOutputStream(jimageFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
DataOutputStream out = new DataOutputStream(bos)) {
@@ -163,9 +162,9 @@ public final class ImageFileCreator {
ByteOrder byteOrder)
throws IOException {
BasicImageWriter writer = new BasicImageWriter(byteOrder);
- PoolImpl allContent = createPools(archives,
+ ModulePoolImpl allContent = createPools(archives,
entriesForModule, byteOrder, writer);
- PoolImpl result = generateJImage(allContent,
+ ModulePoolImpl result = generateJImage(allContent,
writer, plugins, plugins.getJImageFileOutputStream());
//Handle files.
@@ -176,12 +175,12 @@ public final class ImageFileCreator {
}
}
- private static PoolImpl generateJImage(PoolImpl allContent,
+ private static ModulePoolImpl generateJImage(ModulePoolImpl allContent,
BasicImageWriter writer,
ImagePluginStack pluginSupport,
DataOutputStream out
) throws IOException {
- PoolImpl resultResources;
+ ModulePoolImpl resultResources;
try {
resultResources = pluginSupport.visitResources(allContent);
} catch (PluginException pe) {
@@ -190,14 +189,14 @@ public final class ImageFileCreator {
throw new IOException(ex);
}
Set duplicates = new HashSet<>();
- long offset = 0;
+ long[] offset = new long[1];
- List content = new ArrayList<>();
+ List content = new ArrayList<>();
List paths = new ArrayList<>();
// the order of traversing the resources and the order of
// the module content being written must be the same
- for (ModuleData res : resultResources.getContent()) {
- if (res.getType().equals(ModuleDataType.CLASS_OR_RESOURCE)) {
+ resultResources.entries().forEach(res -> {
+ if (res.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
String path = res.getPath();
content.add(res);
long uncompressedSize = res.getLength();
@@ -216,24 +215,24 @@ public final class ImageFileCreator {
// TODO Need to hang bytes on resource and write
// from resource not zip.
// Skipping resource throws off writing from zip.
- offset += onFileSize;
- continue;
+ offset[0] += onFileSize;
+ return;
}
duplicates.add(path);
- writer.addLocation(path, offset, compressedSize, uncompressedSize);
+ writer.addLocation(path, offset[0], compressedSize, uncompressedSize);
paths.add(path);
- offset += onFileSize;
+ offset[0] += onFileSize;
}
- }
+ });
- ImageResourcesTree tree = new ImageResourcesTree(offset, writer, paths);
+ ImageResourcesTree tree = new ImageResourcesTree(offset[0], writer, paths);
// write header and indices
byte[] bytes = writer.getBytes();
out.write(bytes, 0, bytes.length);
// write module content
- for (ModuleData res : content) {
+ for (ModuleEntry res : content) {
byte[] buf = res.getBytes();
out.write(buf, 0, buf.length);
}
@@ -245,26 +244,26 @@ public final class ImageFileCreator {
return resultResources;
}
- private static Pool.ModuleDataType mapImageFileType(EntryType type) {
+ private static ModuleEntry.Type mapImageFileType(EntryType type) {
switch(type) {
case CONFIG: {
- return Pool.ModuleDataType.CONFIG;
+ return ModuleEntry.Type.CONFIG;
}
case NATIVE_CMD: {
- return Pool.ModuleDataType.NATIVE_CMD;
+ return ModuleEntry.Type.NATIVE_CMD;
}
case NATIVE_LIB: {
- return Pool.ModuleDataType.NATIVE_LIB;
+ return ModuleEntry.Type.NATIVE_LIB;
}
}
return null;
}
- private static PoolImpl createPools(Set archives,
+ private static ModulePoolImpl createPools(Set archives,
Map> entriesForModule,
ByteOrder byteOrder,
BasicImageWriter writer) throws IOException {
- PoolImpl resources = new PoolImpl(byteOrder, new StringTable() {
+ ModulePoolImpl resources = new ModulePoolImpl(byteOrder, new StringTable() {
@Override
public int addString(String str) {
@@ -291,7 +290,7 @@ public final class ImageFileCreator {
path = "/" + mn + "/" + path;
}
try {
- resources.add(Pool.newResource(path, bytes));
+ resources.add(ModuleEntry.create(path, bytes));
} catch (Exception ex) {
throw new IOException(ex);
}
@@ -300,7 +299,7 @@ public final class ImageFileCreator {
try {
// Entry.path() contains the kind of file native, conf, bin, ...
// Keep it to avoid naming conflict (eg: native/jvm.cfg and config/jvm.cfg
- resources.add(Pool.newImageFile(mn,
+ resources.add(ModuleEntry.create(mn,
"/" + mn + "/" + entry.path(), mapImageFileType(entry.type()),
entry.stream(), entry.size()));
} catch (Exception ex) {
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginConfiguration.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginConfiguration.java
index 7bd631a8c72..08ff3cb7e64 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginConfiguration.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginConfiguration.java
@@ -28,22 +28,17 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Properties;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.builder.ImageBuilder;
import jdk.tools.jlink.Jlink;
import jdk.tools.jlink.plugin.Plugin;
-import jdk.tools.jlink.plugin.PluginContext;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Plugin.CATEGORY;
-import jdk.tools.jlink.plugin.Pool;
+import jdk.tools.jlink.plugin.Plugin.Category;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.PostProcessorPlugin;
import jdk.tools.jlink.plugin.TransformerPlugin;
@@ -52,17 +47,18 @@ import jdk.tools.jlink.plugin.TransformerPlugin;
*/
public final class ImagePluginConfiguration {
- private static final List CATEGORIES_ORDER = new ArrayList<>();
+ private static final List CATEGORIES_ORDER = new ArrayList<>();
static {
- CATEGORIES_ORDER.add(Plugin.CATEGORY.FILTER);
- CATEGORIES_ORDER.add(Plugin.CATEGORY.TRANSFORMER);
- CATEGORIES_ORDER.add(Plugin.CATEGORY.MODULEINFO_TRANSFORMER);
- CATEGORIES_ORDER.add(Plugin.CATEGORY.SORTER);
- CATEGORIES_ORDER.add(Plugin.CATEGORY.COMPRESSOR);
- CATEGORIES_ORDER.add(Plugin.CATEGORY.VERIFIER);
- CATEGORIES_ORDER.add(Plugin.CATEGORY.PROCESSOR);
- CATEGORIES_ORDER.add(Plugin.CATEGORY.PACKAGER);
+ CATEGORIES_ORDER.add(Plugin.Category.FILTER);
+ CATEGORIES_ORDER.add(Plugin.Category.TRANSFORMER);
+ CATEGORIES_ORDER.add(Plugin.Category.MODULEINFO_TRANSFORMER);
+ CATEGORIES_ORDER.add(Plugin.Category.SORTER);
+ CATEGORIES_ORDER.add(Plugin.Category.COMPRESSOR);
+ CATEGORIES_ORDER.add(Plugin.Category.METAINFO_ADDER);
+ CATEGORIES_ORDER.add(Plugin.Category.VERIFIER);
+ CATEGORIES_ORDER.add(Plugin.Category.PROCESSOR);
+ CATEGORIES_ORDER.add(Plugin.Category.PACKAGER);
}
private ImagePluginConfiguration() {
@@ -76,8 +72,8 @@ public final class ImagePluginConfiguration {
if (pluginsConfiguration == null) {
return new ImagePluginStack();
}
- Map> plugins = new LinkedHashMap<>();
- for (Plugin.CATEGORY cat : CATEGORIES_ORDER) {
+ Map> plugins = new LinkedHashMap<>();
+ for (Plugin.Category cat : CATEGORIES_ORDER) {
plugins.put(cat, new ArrayList<>());
}
@@ -89,7 +85,7 @@ public final class ImagePluginConfiguration {
+ " added more than once to stack ");
}
seen.add(plug.getName());
- CATEGORY category = Utils.getCategory(plug);
+ Category category = Utils.getCategory(plug);
if (category == null) {
throw new PluginException("Invalid category for "
+ plug.getName());
@@ -100,10 +96,10 @@ public final class ImagePluginConfiguration {
List transformerPlugins = new ArrayList<>();
List postProcessingPlugins = new ArrayList<>();
- for (Entry> entry : plugins.entrySet()) {
+ for (Entry> entry : plugins.entrySet()) {
// Sort according to plugin constraints
List orderedPlugins = PluginOrderingGraph.sort(entry.getValue());
- CATEGORY category = entry.getKey();
+ Category category = entry.getKey();
for (Plugin p : orderedPlugins) {
if (Utils.isPostProcessor(category)) {
@SuppressWarnings("unchecked")
@@ -143,14 +139,13 @@ public final class ImagePluginConfiguration {
}
@Override
- public void storeFiles(Pool files) {
+ public void storeFiles(ModulePool files) {
throw new PluginException("No directory setup to store files");
}
};
}
- PluginContext ctxt = pluginsConfiguration.getPluginContext();
return new ImagePluginStack(builder, transformerPlugins,
- lastSorter, postProcessingPlugins, ctxt);
+ lastSorter, postProcessingPlugins);
}
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginStack.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginStack.java
index 6a5db82ccdf..24b8aeb632d 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginStack.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginStack.java
@@ -37,20 +37,21 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Properties;
+import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jdk.internal.jimage.decompressor.Decompressor;
import jdk.tools.jlink.plugin.Plugin;
-import jdk.tools.jlink.plugin.PluginContext;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.builder.ImageBuilder;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
+import jdk.tools.jlink.plugin.ModulePool;
+import jdk.tools.jlink.plugin.LinkModule;
+import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PostProcessorPlugin;
/**
@@ -64,9 +65,9 @@ public final class ImagePluginStack {
ExecutableImage retrieve(ImagePluginStack stack) throws IOException;
}
- public static final class OrderedResourcePool extends PoolImpl {
+ public static final class OrderedResourcePool extends ModulePoolImpl {
- private final List orderedList = new ArrayList<>();
+ private final List orderedList = new ArrayList<>();
public OrderedResourcePool(ByteOrder order, StringTable table) {
super(order, table);
@@ -78,22 +79,22 @@ public final class ImagePluginStack {
* @param resource The Resource to add.
*/
@Override
- public void add(ModuleData resource) {
+ public void add(ModuleEntry resource) {
super.add(resource);
orderedList.add(resource);
}
- List getOrderedList() {
+ List getOrderedList() {
return Collections.unmodifiableList(orderedList);
}
}
- private final static class CheckOrderResourcePool extends PoolImpl {
+ private final static class CheckOrderResourcePool extends ModulePoolImpl {
- private final List orderedList;
+ private final List orderedList;
private int currentIndex;
- public CheckOrderResourcePool(ByteOrder order, List orderedList, StringTable table) {
+ public CheckOrderResourcePool(ByteOrder order, List orderedList, StringTable table) {
super(order, table);
this.orderedList = orderedList;
}
@@ -104,8 +105,8 @@ public final class ImagePluginStack {
* @param resource The Resource to add.
*/
@Override
- public void add(ModuleData resource) {
- ModuleData ordered = orderedList.get(currentIndex);
+ public void add(ModuleEntry resource) {
+ ModuleEntry ordered = orderedList.get(currentIndex);
if (!resource.equals(ordered)) {
throw new PluginException("Resource " + resource.getPath() + " not in the right order");
}
@@ -166,26 +167,16 @@ public final class ImagePluginStack {
private final List resourcePrevisitors = new ArrayList<>();
private final ImageBuilder imageBuilder;
- private final Properties release;
public ImagePluginStack() {
this(null, Collections.emptyList(), null,
- Collections.emptyList(), null);
+ Collections.emptyList());
}
public ImagePluginStack(ImageBuilder imageBuilder,
List contentPlugins,
Plugin lastSorter,
List postprocessingPlugins) {
- this(imageBuilder, contentPlugins, lastSorter,
- postprocessingPlugins, null);
- }
-
- public ImagePluginStack(ImageBuilder imageBuilder,
- List contentPlugins,
- Plugin lastSorter,
- List postprocessingPlugins,
- PluginContext ctxt) {
Objects.requireNonNull(contentPlugins);
this.lastSorter = lastSorter;
for (TransformerPlugin p : contentPlugins) {
@@ -200,7 +191,6 @@ public final class ImagePluginStack {
this.postProcessingPlugins.add(p);
}
this.imageBuilder = imageBuilder;
- this.release = ctxt != null? ctxt.getReleaseProperties() : new Properties();
}
public void operate(ImageProvider provider) throws Exception {
@@ -231,12 +221,12 @@ public final class ImagePluginStack {
* @return The result of the visit.
* @throws IOException
*/
- public PoolImpl visitResources(PoolImpl resources)
+ public ModulePoolImpl visitResources(ModulePoolImpl resources)
throws Exception {
Objects.requireNonNull(resources);
resources.setReadOnly();
if (resources.isEmpty()) {
- return new PoolImpl(resources.getByteOrder(),
+ return new ModulePoolImpl(resources.getByteOrder(),
resources.getStringTable());
}
PreVisitStrings previsit = new PreVisitStrings();
@@ -250,11 +240,11 @@ public final class ImagePluginStack {
resources.getStringTable().addString(s);
}
- PoolImpl current = resources;
- List frozenOrder = null;
+ ModulePoolImpl current = resources;
+ List frozenOrder = null;
for (TransformerPlugin p : contentPlugins) {
current.setReadOnly();
- PoolImpl output = null;
+ ModulePoolImpl output = null;
if (p == lastSorter) {
if (frozenOrder != null) {
throw new Exception("Order of resources is already frozen. Plugin "
@@ -268,7 +258,7 @@ public final class ImagePluginStack {
output = new CheckOrderResourcePool(current.getByteOrder(),
frozenOrder, resources.getStringTable());
} else {
- output = new PoolImpl(current.getByteOrder(),
+ output = new ModulePoolImpl(current.getByteOrder(),
resources.getStringTable());
}
}
@@ -287,15 +277,15 @@ public final class ImagePluginStack {
}
/**
- * This pool wrap the original pool and automatically uncompress moduledata
+ * This pool wrap the original pool and automatically uncompress ModuleEntry
* if needed.
*/
- private class LastPool extends Pool {
- private class LastModule implements Module {
+ private class LastPool implements ModulePool {
+ private class LastModule implements LinkModule {
- private final Module module;
+ final LinkModule module;
- LastModule(Module module) {
+ LastModule(LinkModule module) {
this.module = module;
}
@@ -305,9 +295,9 @@ public final class ImagePluginStack {
}
@Override
- public ModuleData get(String path) {
- ModuleData d = module.get(path);
- return getUncompressed(d);
+ public Optional findEntry(String path) {
+ Optional d = module.findEntry(path);
+ return d.isPresent()? Optional.of(getUncompressed(d.get())) : Optional.empty();
}
@Override
@@ -316,7 +306,7 @@ public final class ImagePluginStack {
}
@Override
- public void add(ModuleData data) {
+ public void add(ModuleEntry data) {
throw new PluginException("pool is readonly");
}
@@ -331,19 +321,24 @@ public final class ImagePluginStack {
}
@Override
- public Collection getContent() {
- List lst = new ArrayList<>();
- for(ModuleData md : module.getContent()) {
+ public Stream entries() {
+ List lst = new ArrayList<>();
+ module.entries().forEach(md -> {
lst.add(getUncompressed(md));
- }
- return lst;
+ });
+ return lst.stream();
+ }
+
+ @Override
+ public int getEntryCount() {
+ return module.getEntryCount();
}
}
- private final PoolImpl pool;
+ private final ModulePoolImpl pool;
Decompressor decompressor = new Decompressor();
- Collection content;
+ Collection content;
- LastPool(PoolImpl pool) {
+ LastPool(ModulePoolImpl pool) {
this.pool = pool;
}
@@ -353,23 +348,14 @@ public final class ImagePluginStack {
}
@Override
- public void add(ModuleData resource) {
+ public void add(ModuleEntry resource) {
throw new PluginException("pool is readonly");
}
- /**
- * Retrieves the module of the provided name.
- *
- * @param name The module name
- * @return the module or null if the module doesn't exist.
- */
@Override
- public Module getModule(String name) {
- Module module = pool.getModule(name);
- if (module != null) {
- module = new LastModule(module);
- }
- return module;
+ public Optional findModule(String name) {
+ Optional module = pool.findModule(name);
+ return module.isPresent()? Optional.of(new LastModule(module.get())) : Optional.empty();
}
/**
@@ -378,45 +364,55 @@ public final class ImagePluginStack {
* @return The collection of modules.
*/
@Override
- public Collection getModules() {
- List modules = new ArrayList<>();
- for (Module m : pool.getModules()) {
+ public Stream extends LinkModule> modules() {
+ List modules = new ArrayList<>();
+ pool.modules().forEach(m -> {
modules.add(new LastModule(m));
- }
- return modules;
+ });
+ return modules.stream();
+ }
+
+ @Override
+ public int getModuleCount() {
+ return pool.getModuleCount();
}
/**
* Get all resources contained in this pool instance.
*
- * @return The collection of resources;
+ * @return The stream of resources;
*/
@Override
- public Collection getContent() {
+ public Stream extends ModuleEntry> entries() {
if (content == null) {
content = new ArrayList<>();
- for (ModuleData md : pool.getContent()) {
+ pool.entries().forEach(md -> {
content.add(getUncompressed(md));
- }
+ });
}
- return content;
+ return content.stream();
+ }
+
+ @Override
+ public int getEntryCount() {
+ return pool.getEntryCount();
}
/**
* Get the resource for the passed path.
*
* @param path A resource path
- * @return A Resource instance or null if the resource is not found
+ * @return A Resource instance if the resource is found
*/
@Override
- public ModuleData get(String path) {
+ public Optional findEntry(String path) {
Objects.requireNonNull(path);
- Pool.ModuleData res = pool.get(path);
- return getUncompressed(res);
+ Optional res = pool.findEntry(path);
+ return res.isPresent()? Optional.of(getUncompressed(res.get())) : Optional.empty();
}
@Override
- public boolean contains(ModuleData res) {
+ public boolean contains(ModuleEntry res) {
return pool.contains(res);
}
@@ -426,8 +422,8 @@ public final class ImagePluginStack {
}
@Override
- public void visit(Visitor visitor, Pool output) {
- pool.visit(visitor, output);
+ public void transformAndCopy(Function visitor, ModulePool output) {
+ pool.transformAndCopy(visitor, output);
}
@Override
@@ -435,14 +431,19 @@ public final class ImagePluginStack {
return pool.getByteOrder();
}
- private ModuleData getUncompressed(ModuleData res) {
+ @Override
+ public Map getReleaseProperties() {
+ return Collections.unmodifiableMap(pool.getReleaseProperties());
+ }
+
+ private ModuleEntry getUncompressed(ModuleEntry res) {
if (res != null) {
- if (res instanceof PoolImpl.CompressedModuleData) {
+ if (res instanceof ModulePoolImpl.CompressedModuleData) {
try {
byte[] bytes = decompressor.decompressResource(getByteOrder(),
(int offset) -> pool.getStringTable().getString(offset),
res.getBytes());
- res = Pool.newResource(res.getPath(),
+ res = ModuleEntry.create(res.getPath(),
new ByteArrayInputStream(bytes),
bytes.length);
} catch (IOException ex) {
@@ -462,20 +463,24 @@ public final class ImagePluginStack {
* @param writer
* @throws java.lang.Exception
*/
- public void storeFiles(PoolImpl original, PoolImpl transformed,
+ public void storeFiles(ModulePoolImpl original, ModulePoolImpl transformed,
BasicImageWriter writer)
throws Exception {
Objects.requireNonNull(original);
- try {
- // fill release information available from transformed "java.base" module!
- ModuleDescriptor desc = transformed.getModule("java.base").getDescriptor();
- desc.osName().ifPresent(s -> release.put("OS_NAME", s));
- desc.osVersion().ifPresent(s -> release.put("OS_VERSION", s));
- desc.osArch().ifPresent(s -> release.put("OS_ARCH", s));
- } catch (Exception ignored) {
- }
+ Objects.requireNonNull(transformed);
+ Optional javaBase = transformed.findModule("java.base");
+ javaBase.ifPresent(mod -> {
+ try {
+ Map release = transformed.getReleaseProperties();
+ // fill release information available from transformed "java.base" module!
+ ModuleDescriptor desc = mod.getDescriptor();
+ desc.osName().ifPresent(s -> release.put("OS_NAME", s));
+ desc.osVersion().ifPresent(s -> release.put("OS_VERSION", s));
+ desc.osArch().ifPresent(s -> release.put("OS_ARCH", s));
+ } catch (Exception ignored) {}
+ });
- imageBuilder.storeFiles(new LastPool(transformed), release);
+ imageBuilder.storeFiles(new LastPool(transformed));
}
public ExecutableImage getExecutableImage() throws IOException {
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ModuleEntryImpl.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ModuleEntryImpl.java
new file mode 100644
index 00000000000..30c07a3b2d7
--- /dev/null
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ModuleEntryImpl.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 jdk.tools.jlink.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.util.Objects;
+import jdk.tools.jlink.plugin.ModuleEntry;
+
+/**
+ * A LinkModuleEntry is the elementary unit of data inside an image. It is
+ * generally a file. e.g.: a java class file, a resource file, a shared library,
+ * ...
+ *
+ * A LinkModuleEntry is identified by a path of the form:
+ *
+ * - For jimage content: /{module name}/{package1}/.../{packageN}/{file
+ * name}
+ * - For other files (shared lib, launchers, config, ...):/{module name}/
+ * {@literal bin|conf|native}/{dir1}>/.../{dirN}/{file name}
+ *
+ */
+public class ModuleEntryImpl implements ModuleEntry {
+
+ private final Type type;
+ private final String path;
+ private final String module;
+ private final long length;
+ private final InputStream stream;
+ private byte[] buffer;
+
+ /**
+ * Create a new LinkModuleEntry.
+ *
+ * @param module The module name.
+ * @param path The data path identifier.
+ * @param type The data type.
+ * @param stream The data content stream.
+ * @param length The stream length.
+ */
+ public ModuleEntryImpl(String module, String path, Type type, InputStream stream, long length) {
+ Objects.requireNonNull(module);
+ Objects.requireNonNull(path);
+ Objects.requireNonNull(type);
+ Objects.requireNonNull(stream);
+ this.path = path;
+ this.type = type;
+ this.module = module;
+ this.stream = stream;
+ this.length = length;
+ }
+
+ /**
+ * The LinkModuleEntry module name.
+ *
+ * @return The module name.
+ */
+ @Override
+ public final String getModule() {
+ return module;
+ }
+
+ /**
+ * The LinkModuleEntry path.
+ *
+ * @return The module path.
+ */
+ @Override
+ public final String getPath() {
+ return path;
+ }
+
+ /**
+ * The LinkModuleEntry's type.
+ *
+ * @return The data type.
+ */
+ @Override
+ public final Type getType() {
+ return type;
+ }
+
+ /**
+ * The LinkModuleEntry content as an array of byte.
+ *
+ * @return An Array of bytes.
+ */
+ @Override
+ public byte[] getBytes() {
+ if (buffer == null) {
+ try (InputStream is = stream) {
+ buffer = is.readAllBytes();
+ } catch (IOException ex) {
+ throw new UncheckedIOException(ex);
+ }
+ }
+ return buffer;
+ }
+
+ /**
+ * The LinkModuleEntry content length.
+ *
+ * @return The length.
+ */
+ @Override
+ public long getLength() {
+ return length;
+ }
+
+ /**
+ * The LinkModuleEntry stream.
+ *
+ * @return The module data stream.
+ */
+ @Override
+ public InputStream stream() {
+ return stream;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 89 * hash + Objects.hashCode(this.path);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof ModuleEntryImpl)) {
+ return false;
+ }
+ ModuleEntryImpl f = (ModuleEntryImpl) other;
+ return f.path.equals(path);
+ }
+
+ @Override
+ public String toString() {
+ return getPath();
+ }
+}
\ No newline at end of file
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ModulePoolImpl.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ModulePoolImpl.java
new file mode 100644
index 00000000000..a572fa48637
--- /dev/null
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ModulePoolImpl.java
@@ -0,0 +1,421 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 jdk.tools.jlink.internal;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.lang.module.ModuleDescriptor;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Stream;
+import jdk.internal.jimage.decompressor.CompressedResourceHeader;
+import jdk.tools.jlink.plugin.ModulePool;
+import jdk.tools.jlink.plugin.LinkModule;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.PluginException;
+import jdk.tools.jlink.internal.plugins.FileCopierPlugin;
+
+/**
+ * Pool of module data.
+ */
+public class ModulePoolImpl implements ModulePool {
+
+ private class ModuleImpl implements LinkModule {
+
+ final Map moduleContent = new LinkedHashMap<>();
+ private ModuleDescriptor descriptor;
+ final String name;
+
+ private ModuleImpl(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Optional findEntry(String path) {
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ if (!path.startsWith("/" + name)) {
+ path = "/" + name + path;
+ }
+ return Optional.ofNullable(moduleContent.get(path));
+ }
+
+ @Override
+ public ModuleDescriptor getDescriptor() {
+ if (descriptor == null) {
+ String p = "/" + name + "/module-info.class";
+ Optional content = findEntry(p);
+ if (!content.isPresent()) {
+ throw new PluginException("No module-info for " + name
+ + " module");
+ }
+ ByteBuffer bb = ByteBuffer.wrap(content.get().getBytes());
+ descriptor = ModuleDescriptor.read(bb);
+ }
+ return descriptor;
+ }
+
+ @Override
+ public void add(ModuleEntry data) {
+ if (isReadOnly()) {
+ throw new PluginException("LinkConfiguration is readonly");
+ }
+ Objects.requireNonNull(data);
+ if (!data.getModule().equals(name)) {
+ throw new PluginException("Can't add resource " + data.getPath()
+ + " to module " + name);
+ }
+ ModulePoolImpl.this.add(data);
+ }
+
+ @Override
+ public Set getAllPackages() {
+ Set pkgs = new HashSet<>();
+ moduleContent.values().stream().filter(m -> m.getType().
+ equals(ModuleEntry.Type.CLASS_OR_RESOURCE)).forEach(res -> {
+ // Module metadata only contains packages with .class files
+ if (ImageFileCreator.isClassPackage(res.getPath())) {
+ String[] split = ImageFileCreator.splitPath(res.getPath());
+ String pkg = split[1];
+ if (pkg != null && !pkg.isEmpty()) {
+ pkgs.add(pkg);
+ }
+ }
+ });
+ return pkgs;
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+
+ @Override
+ public Stream extends ModuleEntry> entries() {
+ return moduleContent.values().stream();
+ }
+
+ @Override
+ public int getEntryCount() {
+ return moduleContent.values().size();
+ }
+ }
+
+ private final Map resources = new LinkedHashMap<>();
+ private final Map modules = new LinkedHashMap<>();
+ private final ModuleImpl fileCopierModule = new ModuleImpl(FileCopierPlugin.FAKE_MODULE);
+ private Map releaseProps = new HashMap<>();
+
+ private final ByteOrder order;
+
+ private boolean isReadOnly;
+ private final StringTable table;
+
+ public ModulePoolImpl() {
+ this(ByteOrder.nativeOrder());
+ }
+
+ public ModulePoolImpl(ByteOrder order) {
+ this(order, new StringTable() {
+
+ @Override
+ public int addString(String str) {
+ return -1;
+ }
+
+ @Override
+ public String getString(int id) {
+ return null;
+ }
+ });
+ }
+
+ public ModulePoolImpl(ByteOrder order, StringTable table) {
+ this.order = order;
+ this.table = table;
+ }
+
+ /**
+ * Add a ModuleEntry.
+ *
+ * @param data The ModuleEntry to add.
+ */
+ @Override
+ public void add(ModuleEntry data) {
+ if (isReadOnly()) {
+ throw new PluginException("LinkConfiguration is readonly");
+ }
+ Objects.requireNonNull(data);
+ if (resources.get(data.getPath()) != null) {
+ throw new PluginException("Resource " + data.getPath()
+ + " already present");
+ }
+ String modulename = data.getModule();
+ ModuleImpl m = modules.get(modulename);
+ // ## TODO: FileCopierPlugin should not add content to a module
+ // FAKE_MODULE is not really a module to be added in the image
+ if (FileCopierPlugin.FAKE_MODULE.equals(modulename)) {
+ m = fileCopierModule;
+ }
+ if (m == null) {
+ m = new ModuleImpl(modulename);
+ modules.put(modulename, m);
+ }
+ resources.put(data.getPath(), data);
+ m.moduleContent.put(data.getPath(), data);
+ }
+
+ /**
+ * Retrieves the module for the provided name.
+ *
+ * @param name The module name
+ * @return the module of matching name, if found
+ */
+ @Override
+ public Optional findModule(String name) {
+ Objects.requireNonNull(name);
+ return Optional.ofNullable(modules.get(name));
+ }
+
+ /**
+ * The stream of modules contained in this LinkConfiguration.
+ *
+ * @return The stream of modules.
+ */
+ @Override
+ public Stream extends LinkModule> modules() {
+ return modules.values().stream();
+ }
+
+ /**
+ * Return the number of LinkModule count in this LinkConfiguration.
+ *
+ * @return the module count.
+ */
+ @Override
+ public int getModuleCount() {
+ return modules.size();
+ }
+
+ /**
+ * Get all ModuleEntry contained in this LinkConfiguration instance.
+ *
+ * @return The stream of LinkModuleEntries.
+ */
+ @Override
+ public Stream extends ModuleEntry> entries() {
+ return resources.values().stream();
+ }
+
+ /**
+ * Return the number of ModuleEntry count in this LinkConfiguration.
+ *
+ * @return the entry count.
+ */
+ @Override
+ public int getEntryCount() {
+ return resources.values().size();
+ }
+
+ /**
+ * Get the ModuleEntry for the passed path.
+ *
+ * @param path A data path
+ * @return A ModuleEntry instance or null if the data is not found
+ */
+ @Override
+ public Optional findEntry(String path) {
+ Objects.requireNonNull(path);
+ return Optional.ofNullable(resources.get(path));
+ }
+
+ /**
+ * Check if the LinkConfiguration contains the given ModuleEntry.
+ *
+ * @param data The module data to check existence for.
+ * @return The module data or null if not found.
+ */
+ @Override
+ public boolean contains(ModuleEntry data) {
+ Objects.requireNonNull(data);
+ return findEntry(data.getPath()).isPresent();
+ }
+
+ /**
+ * Check if the LinkConfiguration contains some content at all.
+ *
+ * @return True, no content, false otherwise.
+ */
+ @Override
+ public boolean isEmpty() {
+ return resources.isEmpty();
+ }
+
+ /**
+ * Visit each ModuleEntry in this LinkConfiguration to transform it and
+ * copy the transformed ModuleEntry to the output LinkConfiguration.
+ *
+ * @param transform The function called for each ModuleEntry found in
+ * the LinkConfiguration. The transform function should return a
+ * ModuleEntry instance which will be added to the output or it should
+ * return null if the passed ModuleEntry is to be ignored for the
+ * output.
+ *
+ * @param output The LinkConfiguration to be filled with Visitor returned
+ * ModuleEntry.
+ */
+ @Override
+ public void transformAndCopy(Function transform,
+ ModulePool output) {
+ entries().forEach(resource -> {
+ ModuleEntry res = transform.apply(resource);
+ if (res != null) {
+ output.add(res);
+ }
+ });
+ }
+
+ /**
+ * The ByteOrder currently in use when generating the jimage file.
+ *
+ * @return The ByteOrder.
+ */
+ @Override
+ public ByteOrder getByteOrder() {
+ return order;
+ }
+
+ @Override
+ public Map getReleaseProperties() {
+ return isReadOnly()? Collections.unmodifiableMap(releaseProps) : releaseProps;
+ }
+
+ public StringTable getStringTable() {
+ return table;
+ }
+
+ /**
+ * Make this Resources instance read-only. No resource can be added.
+ */
+ public void setReadOnly() {
+ isReadOnly = true;
+ }
+
+ /**
+ * Read only state.
+ *
+ * @return true if readonly false otherwise.
+ */
+ @Override
+ public boolean isReadOnly() {
+ return isReadOnly;
+ }
+
+ /**
+ * A resource that has been compressed.
+ */
+ public static final class CompressedModuleData extends ModuleEntryImpl {
+
+ final long uncompressed_size;
+
+ private CompressedModuleData(String module, String path,
+ InputStream stream, long size,
+ long uncompressed_size) {
+ super(module, path, ModuleEntry.Type.CLASS_OR_RESOURCE, stream, size);
+ this.uncompressed_size = uncompressed_size;
+ }
+
+ public long getUncompressedSize() {
+ return uncompressed_size;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof CompressedModuleData)) {
+ return false;
+ }
+ CompressedModuleData f = (CompressedModuleData) other;
+ return f.getPath().equals(getPath());
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+ }
+
+ public static CompressedModuleData newCompressedResource(ModuleEntry original,
+ ByteBuffer compressed,
+ String plugin, String pluginConfig, StringTable strings,
+ ByteOrder order) {
+ Objects.requireNonNull(original);
+ Objects.requireNonNull(compressed);
+ Objects.requireNonNull(plugin);
+
+ boolean isTerminal = !(original instanceof CompressedModuleData);
+ long uncompressed_size = original.getLength();
+ if (original instanceof CompressedModuleData) {
+ CompressedModuleData comp = (CompressedModuleData) original;
+ uncompressed_size = comp.getUncompressedSize();
+ }
+ int nameOffset = strings.addString(plugin);
+ int configOffset = -1;
+ if (pluginConfig != null) {
+ configOffset = strings.addString(plugin);
+ }
+ CompressedResourceHeader rh
+ = new CompressedResourceHeader(compressed.limit(), original.getLength(),
+ nameOffset, configOffset, isTerminal);
+ // Merge header with content;
+ byte[] h = rh.getBytes(order);
+ ByteBuffer bb = ByteBuffer.allocate(compressed.limit() + h.length);
+ bb.order(order);
+ bb.put(h);
+ bb.put(compressed);
+ byte[] contentWithHeader = bb.array();
+
+ CompressedModuleData compressedResource
+ = new CompressedModuleData(original.getModule(), original.getPath(),
+ new ByteArrayInputStream(contentWithHeader),
+ contentWithHeader.length, uncompressed_size);
+ return compressedResource;
+ }
+
+}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginContextImpl.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginContextImpl.java
deleted file mode 100644
index 7fe7dcea36e..00000000000
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PluginContextImpl.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2016, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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 jdk.tools.jlink.internal;
-
-import java.util.Properties;
-
-import jdk.tools.jlink.plugin.PluginContext;
-
-public final class PluginContextImpl implements PluginContext {
- private final Properties releaseProps = new Properties();
-
- public Properties getReleaseProperties() {
- return releaseProps;
- }
-}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PoolImpl.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PoolImpl.java
deleted file mode 100644
index 2b1dd827bae..00000000000
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/PoolImpl.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 2015, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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 jdk.tools.jlink.internal;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.Objects;
-import jdk.internal.jimage.decompressor.CompressedResourceHeader;
-import jdk.tools.jlink.plugin.Pool;
-
-/**
- * Pool of module data.
- */
-public class PoolImpl extends Pool {
-
- /**
- * A resource that has been compressed.
- */
- public static final class CompressedModuleData extends ModuleData {
-
- private final long uncompressed_size;
-
- private CompressedModuleData(String module, String path,
- InputStream stream, long size,
- long uncompressed_size) {
- super(module, path, ModuleDataType.CLASS_OR_RESOURCE, stream, size);
- this.uncompressed_size = uncompressed_size;
- }
-
- public long getUncompressedSize() {
- return uncompressed_size;
- }
-
- @Override
- public boolean equals(Object other) {
- if (!(other instanceof CompressedModuleData)) {
- return false;
- }
- CompressedModuleData f = (CompressedModuleData) other;
- return f.getPath().equals(getPath());
- }
-
- @Override
- public int hashCode() {
- return super.hashCode();
- }
- }
-
- private boolean isReadOnly;
- private final StringTable table;
-
- public PoolImpl() {
- this(ByteOrder.nativeOrder(), new StringTable() {
-
- @Override
- public int addString(String str) {
- return -1;
- }
- @Override
- public String getString(int id) {
- return null;
- }
- });
- }
-
- public PoolImpl(ByteOrder order) {
- this(order, new StringTable() {
-
- @Override
- public int addString(String str) {
- return -1;
- }
- @Override
- public String getString(int id) {
- return null;
- }
- });
- }
-
- public PoolImpl(ByteOrder order, StringTable table) {
- super(order);
- this.table = table;
- }
-
- public StringTable getStringTable() {
- return table;
- }
-
- /**
- * Make this Resources instance read-only. No resource can be added.
- */
- public void setReadOnly() {
- isReadOnly = true;
- }
-
- /**
- * Read only state.
- *
- * @return true if readonly false otherwise.
- */
- @Override
- public boolean isReadOnly() {
- return isReadOnly;
- }
-
- public static CompressedModuleData newCompressedResource(ModuleData original,
- ByteBuffer compressed,
- String plugin, String pluginConfig, StringTable strings,
- ByteOrder order) {
- Objects.requireNonNull(original);
- Objects.requireNonNull(compressed);
- Objects.requireNonNull(plugin);
-
- boolean isTerminal = !(original instanceof CompressedModuleData);
- long uncompressed_size = original.getLength();
- if (original instanceof CompressedModuleData) {
- CompressedModuleData comp = (CompressedModuleData) original;
- uncompressed_size = comp.getUncompressedSize();
- }
- int nameOffset = strings.addString(plugin);
- int configOffset = -1;
- if (pluginConfig != null) {
- configOffset = strings.addString(plugin);
- }
- CompressedResourceHeader rh
- = new CompressedResourceHeader(compressed.limit(), original.getLength(),
- nameOffset, configOffset, isTerminal);
- // Merge header with content;
- byte[] h = rh.getBytes(order);
- ByteBuffer bb = ByteBuffer.allocate(compressed.limit() + h.length);
- bb.order(order);
- bb.put(h);
- bb.put(compressed);
- byte[] contentWithHeader = bb.array();
-
- CompressedModuleData compressedResource
- = new CompressedModuleData(original.getModule(), original.getPath(),
- new ByteArrayInputStream(contentWithHeader),
- contentWithHeader.length, uncompressed_size);
- return compressedResource;
- }
-
-}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePrevisitor.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePrevisitor.java
index d9c5bab9a61..c8b8bc79ed6 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePrevisitor.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePrevisitor.java
@@ -24,7 +24,7 @@
*/
package jdk.tools.jlink.internal;
-import jdk.tools.jlink.plugin.Pool;
+import jdk.tools.jlink.plugin.ModulePool;
/**
* Plugin wishing to pre-visit the resources must implement this interface.
@@ -44,5 +44,5 @@ public interface ResourcePrevisitor {
* usage.
* @throws PluginException
*/
- public void previsit(Pool resources, StringTable strings);
+ public void previsit(ModulePool resources, StringTable strings);
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java
index 31064ab79d6..b255312bbf4 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java
@@ -52,7 +52,7 @@ import jdk.internal.module.ConfigurableModuleFinder.Phase;
import jdk.tools.jlink.Jlink;
import jdk.tools.jlink.Jlink.PluginsConfiguration;
import jdk.tools.jlink.plugin.Plugin;
-import jdk.tools.jlink.plugin.Plugin.CATEGORY;
+import jdk.tools.jlink.plugin.Plugin.Category;
import jdk.tools.jlink.builder.DefaultImageBuilder;
import jdk.tools.jlink.builder.ImageBuilder;
import jdk.tools.jlink.plugin.PluginException;
@@ -346,7 +346,6 @@ public final class TaskHelper {
}
}
- PluginContextImpl pluginContext = new PluginContextImpl();
List pluginsList = new ArrayList<>();
for (Entry>> entry : pluginToMaps.entrySet()) {
Plugin plugin = entry.getKey();
@@ -356,7 +355,7 @@ public final class TaskHelper {
// we call configure once for each occurrence. It is upto the plugin
// to 'merge' and/or 'override' arguments.
for (Map map : argsMaps) {
- plugin.configure(Collections.unmodifiableMap(map), pluginContext);
+ plugin.configure(Collections.unmodifiableMap(map));
}
if (!Utils.isDisabled(plugin)) {
@@ -371,7 +370,7 @@ public final class TaskHelper {
}
return new Jlink.PluginsConfiguration(pluginsList,
- builder, lastSorter, pluginContext);
+ builder, lastSorter);
}
}
@@ -594,7 +593,7 @@ public final class TaskHelper {
+ ": " + plugin.getClass().getName());
log.println(bundleHelper.getMessage("main.plugin.module")
+ ": " + plugin.getClass().getModule().getName());
- CATEGORY category = Utils.getCategory(plugin);
+ Category category = Utils.getCategory(plugin);
log.println(bundleHelper.getMessage("main.plugin.category")
+ ": " + category.getName());
log.println(bundleHelper.getMessage("main.plugin.state")
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Utils.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Utils.java
index a8a9a45a5f4..0e29969a034 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Utils.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Utils.java
@@ -30,7 +30,6 @@ import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import jdk.tools.jlink.plugin.Plugin;
-import jdk.tools.jlink.plugin.Plugin.PluginType;
public class Utils {
@@ -50,25 +49,26 @@ public class Utils {
return arguments;
};
- public static boolean isPostProcessor(Plugin.CATEGORY category) {
- return category.equals(Plugin.CATEGORY.VERIFIER)
- || category.equals(Plugin.CATEGORY.PROCESSOR)
- || category.equals(Plugin.CATEGORY.PACKAGER);
+ public static boolean isPostProcessor(Plugin.Category category) {
+ return category.equals(Plugin.Category.VERIFIER)
+ || category.equals(Plugin.Category.PROCESSOR)
+ || category.equals(Plugin.Category.PACKAGER);
}
- public static boolean isPreProcessor(Plugin.CATEGORY category) {
- return category.equals(Plugin.CATEGORY.COMPRESSOR)
- || category.equals(Plugin.CATEGORY.FILTER)
- || category.equals(Plugin.CATEGORY.MODULEINFO_TRANSFORMER)
- || category.equals(Plugin.CATEGORY.SORTER)
- || category.equals(Plugin.CATEGORY.TRANSFORMER);
+ public static boolean isPreProcessor(Plugin.Category category) {
+ return category.equals(Plugin.Category.COMPRESSOR)
+ || category.equals(Plugin.Category.FILTER)
+ || category.equals(Plugin.Category.MODULEINFO_TRANSFORMER)
+ || category.equals(Plugin.Category.SORTER)
+ || category.equals(Plugin.Category.TRANSFORMER)
+ || category.equals(Plugin.Category.METAINFO_ADDER);
}
public static boolean isPostProcessor(Plugin prov) {
if (prov.getType() != null) {
- for (PluginType pt : prov.getType()) {
- if (pt instanceof Plugin.CATEGORY) {
- return isPostProcessor((Plugin.CATEGORY) pt);
+ for (Plugin.Category pt : prov.getType()) {
+ if (pt instanceof Plugin.Category) {
+ return isPostProcessor(pt);
}
}
}
@@ -77,20 +77,20 @@ public class Utils {
public static boolean isPreProcessor(Plugin prov) {
if (prov.getType() != null) {
- for (PluginType pt : prov.getType()) {
- if (pt instanceof Plugin.CATEGORY) {
- return isPreProcessor((Plugin.CATEGORY) pt);
+ for (Plugin.Category pt : prov.getType()) {
+ if (pt instanceof Plugin.Category) {
+ return isPreProcessor(pt);
}
}
}
return false;
}
- public static Plugin.CATEGORY getCategory(Plugin provider) {
+ public static Plugin.Category getCategory(Plugin provider) {
if (provider.getType() != null) {
- for (Plugin.PluginType t : provider.getType()) {
- if (t instanceof Plugin.CATEGORY) {
- return (Plugin.CATEGORY) t;
+ for (Plugin.Category t : provider.getType()) {
+ if (t instanceof Plugin.Category) {
+ return t;
}
}
}
@@ -140,15 +140,15 @@ public class Utils {
}
public static boolean isFunctional(Plugin prov) {
- return prov.getState().contains(Plugin.STATE.FUNCTIONAL);
+ return prov.getState().contains(Plugin.State.FUNCTIONAL);
}
public static boolean isAutoEnabled(Plugin prov) {
- return prov.getState().contains(Plugin.STATE.AUTO_ENABLED);
+ return prov.getState().contains(Plugin.State.AUTO_ENABLED);
}
public static boolean isDisabled(Plugin prov) {
- return prov.getState().contains(Plugin.STATE.DISABLED);
+ return prov.getState().contains(Plugin.State.DISABLED);
}
// is this a builtin (jdk.jlink) plugin?
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/packager/AppRuntimeImageBuilder.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/packager/AppRuntimeImageBuilder.java
index e448acd0b1d..874b338c93f 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/packager/AppRuntimeImageBuilder.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/packager/AppRuntimeImageBuilder.java
@@ -30,7 +30,7 @@ import jdk.tools.jlink.Jlink;
import jdk.tools.jlink.builder.ImageBuilder;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.builder.*;
-import jdk.tools.jlink.plugin.Pool;
+import jdk.tools.jlink.plugin.ModulePool;
import java.io.ByteArrayOutputStream;
import java.io.File;
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java
index aa068f1136e..43eb6f27dec 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java
@@ -26,16 +26,13 @@ package jdk.tools.jlink.internal.plugins;
import java.io.IOException;
import java.io.UncheckedIOException;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.internal.PoolImpl;
-import jdk.tools.jlink.plugin.Pool;
+import jdk.tools.jlink.internal.ModulePoolImpl;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.internal.ImagePluginStack;
import jdk.tools.jlink.internal.ResourcePrevisitor;
@@ -62,10 +59,10 @@ public final class DefaultCompressPlugin implements TransformerPlugin, ResourceP
}
@Override
- public void visit(Pool in, Pool out) {
+ public void visit(ModulePool in, ModulePool out) {
if (ss != null && zip != null) {
- Pool output = new ImagePluginStack.OrderedResourcePool(in.getByteOrder(),
- ((PoolImpl) in).getStringTable());
+ ModulePool output = new ImagePluginStack.OrderedResourcePool(in.getByteOrder(),
+ ((ModulePoolImpl) in).getStringTable());
ss.visit(in, output);
zip.visit(output, out);
} else if (ss != null) {
@@ -76,16 +73,16 @@ public final class DefaultCompressPlugin implements TransformerPlugin, ResourceP
}
@Override
- public void previsit(Pool resources, StringTable strings) {
+ public void previsit(ModulePool resources, StringTable strings) {
if (ss != null) {
ss.previsit(resources, strings);
}
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.COMPRESSOR);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.COMPRESSOR);
return Collections.unmodifiableSet(set);
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeFilesPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeFilesPlugin.java
index 0271670e4c1..628d8f6346e 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeFilesPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeFilesPlugin.java
@@ -32,8 +32,8 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import jdk.tools.jlink.plugin.TransformerPlugin;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleDataType;
+import jdk.tools.jlink.plugin.ModulePool;
+import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.internal.Utils;
/**
@@ -51,9 +51,9 @@ public final class ExcludeFilesPlugin implements TransformerPlugin {
}
@Override
- public void visit(Pool in, Pool out) {
- in.visit((file) -> {
- if (!file.getType().equals(ModuleDataType.CLASS_OR_RESOURCE)) {
+ public void visit(ModulePool in, ModulePool out) {
+ in.transformAndCopy((file) -> {
+ if (!file.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
file = predicate.test(file.getPath()) ? file : null;
}
return file;
@@ -61,9 +61,9 @@ public final class ExcludeFilesPlugin implements TransformerPlugin {
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.FILTER);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludePlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludePlugin.java
index 6d4737a4661..626087b76be 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludePlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludePlugin.java
@@ -32,7 +32,8 @@ import java.util.Set;
import java.util.function.Predicate;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.TransformerPlugin;
-import jdk.tools.jlink.plugin.Pool;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.internal.Utils;
/**
@@ -50,9 +51,9 @@ public final class ExcludePlugin implements TransformerPlugin {
}
@Override
- public void visit(Pool in, Pool out) {
- in.visit((resource) -> {
- if (resource.getType().equals(Pool.ModuleDataType.CLASS_OR_RESOURCE)) {
+ public void visit(ModulePool in, ModulePool out) {
+ in.transformAndCopy((resource) -> {
+ if (resource.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
resource = predicate.test(resource.getPath()) ? resource : null;
}
return resource;
@@ -75,9 +76,9 @@ public final class ExcludePlugin implements TransformerPlugin {
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.FILTER);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java
index 4d502904c37..753d63e5cfc 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java
@@ -40,9 +40,10 @@ import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import jdk.tools.jlink.plugin.TransformerPlugin;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleDataType;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.internal.Utils;
+import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
/**
@@ -102,24 +103,24 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
* e.g.: /java.base/native/amd64/server/libjvm.so
* /java.base/native/server/libjvm.dylib
*/
- private List getVMs(Pool in) {
+ private List getVMs(ModulePool in) {
String jvmlib = jvmlib();
- List ret = in.getModule("java.base").getContent().stream().filter((t) -> {
+ List ret = in.findModule("java.base").get().entries().filter((t) -> {
return t.getPath().endsWith("/" + jvmlib);
}).collect(Collectors.toList());
return ret;
}
@Override
- public void visit(Pool in, Pool out) {
+ public void visit(ModulePool in, ModulePool out) {
String jvmlib = jvmlib();
TreeSet existing = new TreeSet<>(new JvmComparator());
TreeSet removed = new TreeSet<>(new JvmComparator());
if (!keepAll) {
// First retrieve all available VM names and removed VM
- List jvms = getVMs(in);
+ List jvms = getVMs(in);
for (Jvm jvm : Jvm.values()) {
- for (Pool.ModuleData md : jvms) {
+ for (ModuleEntry md : jvms) {
if (md.getPath().endsWith("/" + jvm.getName() + "/" + jvmlib)) {
existing.add(jvm);
if (isRemoved(md)) {
@@ -137,9 +138,9 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
}
// Rewrite the jvm.cfg file.
- in.visit((file) -> {
+ in.transformAndCopy((file) -> {
if (!keepAll) {
- if (file.getType().equals(ModuleDataType.NATIVE_LIB)) {
+ if (file.getType().equals(ModuleEntry.Type.NATIVE_LIB)) {
if (file.getPath().endsWith(JVM_CFG)) {
try {
file = handleJvmCfgFile(file, existing, removed);
@@ -155,14 +156,14 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
}
- private boolean isRemoved(Pool.ModuleData file) {
+ private boolean isRemoved(ModuleEntry file) {
return !predicate.test(file.getPath());
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.FILTER);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
}
@@ -217,7 +218,7 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
}
}
- private Pool.ModuleData handleJvmCfgFile(Pool.ModuleData orig,
+ private ModuleEntry handleJvmCfgFile(ModuleEntry orig,
TreeSet existing,
TreeSet removed) throws IOException {
if (keepAll) {
@@ -253,7 +254,7 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
byte[] content = builder.toString().getBytes(StandardCharsets.UTF_8);
- return Pool.newImageFile(orig.getModule(),
+ return ModuleEntry.create(orig.getModule(),
orig.getPath(),
orig.getType(),
new ByteArrayInputStream(content), content.length);
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/FileCopierPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/FileCopierPlugin.java
index 7a51d6cbcdf..497d97e50a6 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/FileCopierPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/FileCopierPlugin.java
@@ -41,10 +41,10 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import jdk.tools.jlink.internal.ModuleEntryImpl;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
-import jdk.tools.jlink.plugin.Pool.ModuleDataType;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.internal.Utils;
@@ -68,12 +68,12 @@ public class FileCopierPlugin implements TransformerPlugin {
/**
* Symbolic link to another path.
*/
- public static abstract class SymImageFile extends Pool.ModuleData {
+ public static abstract class SymImageFile extends ModuleEntryImpl {
private final String targetPath;
public SymImageFile(String targetPath, String module, String path,
- Pool.ModuleDataType type, InputStream stream, long size) {
+ ModuleEntry.Type type, InputStream stream, long size) {
super(module, path, type, stream, size);
this.targetPath = targetPath;
}
@@ -86,7 +86,7 @@ public class FileCopierPlugin implements TransformerPlugin {
private static final class SymImageFileImpl extends SymImageFile {
public SymImageFileImpl(String targetPath, Path file, String module,
- String path, ModuleDataType type) {
+ String path, ModuleEntry.Type type) {
super(targetPath, module, path, type, newStream(file), length(file));
}
}
@@ -110,11 +110,11 @@ public class FileCopierPlugin implements TransformerPlugin {
private static final class DirectoryCopy implements FileVisitor {
private final Path source;
- private final Pool pool;
+ private final ModulePool pool;
private final String targetDir;
private final List symlinks = new ArrayList<>();
- DirectoryCopy(Path source, Pool pool, String targetDir) {
+ DirectoryCopy(Path source, ModulePool pool, String targetDir) {
this.source = source;
this.pool = pool;
this.targetDir = targetDir;
@@ -148,7 +148,7 @@ public class FileCopierPlugin implements TransformerPlugin {
}
SymImageFileImpl impl = new SymImageFileImpl(symTarget.toString(),
file, path, Objects.requireNonNull(file.getFileName()).toString(),
- Pool.ModuleDataType.OTHER);
+ ModuleEntry.Type.OTHER);
symlinks.add(impl);
} else {
addFile(pool, file, path);
@@ -172,14 +172,14 @@ public class FileCopierPlugin implements TransformerPlugin {
}
}
- private static void addFile(Pool pool, Path file, String path)
+ private static void addFile(ModulePool pool, Path file, String path)
throws IOException {
Objects.requireNonNull(pool);
Objects.requireNonNull(file);
Objects.requireNonNull(path);
- ModuleData impl = Pool.newImageFile(FAKE_MODULE,
+ ModuleEntry impl = ModuleEntry.create(FAKE_MODULE,
"/" + FAKE_MODULE + "/other/" + path,
- Pool.ModuleDataType.OTHER, newStream(file), length(file));
+ ModuleEntry.Type.OTHER, newStream(file), length(file));
try {
pool.add(impl);
} catch (Exception ex) {
@@ -188,9 +188,9 @@ public class FileCopierPlugin implements TransformerPlugin {
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.TRANSFORMER);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@@ -239,8 +239,8 @@ public class FileCopierPlugin implements TransformerPlugin {
}
@Override
- public void visit(Pool in, Pool out) {
- in.visit((file) -> {
+ public void visit(ModulePool in, ModulePool out) {
+ in.transformAndCopy((file) -> {
return file;
}, out);
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java
index d2b2995bdda..9e0805ec361 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java
@@ -33,8 +33,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
/**
@@ -60,8 +61,8 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
}
@Override
- public Set getType() {
- return Collections.singleton(CATEGORY.TRANSFORMER);
+ public Set getType() {
+ return Collections.singleton(Category.TRANSFORMER);
}
@Override
@@ -75,8 +76,8 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
}
@Override
- public Set getState() {
- return EnumSet.of(STATE.AUTO_ENABLED, STATE.FUNCTIONAL);
+ public Set getState() {
+ return EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL);
}
@Override
@@ -151,8 +152,8 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
}
@Override
- public void visit(Pool in, Pool out) {
- for (Pool.ModuleData data : in.getContent()) {
+ public void visit(ModulePool in, ModulePool out) {
+ in.entries().forEach(data -> {
if (("/java.base/" + BMH + ".class").equals(data.getPath())) {
// Add BoundMethodHandle unchanged
out.add(data);
@@ -162,11 +163,11 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
out.add(data);
}
}
- }
+ });
}
@SuppressWarnings("unchecked")
- private void generateConcreteClass(String types, Pool.ModuleData data, Pool out) {
+ private void generateConcreteClass(String types, ModuleEntry data, ModulePool out) {
try {
// Generate class
Map.Entry result = (Map.Entry)
@@ -175,9 +176,9 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
byte[] bytes = result.getValue();
// Add class to pool
- Pool.ModuleData ndata = new Pool.ModuleData(data.getModule(),
+ ModuleEntry ndata = ModuleEntry.create(data.getModule(),
"/java.base/" + className + ".class",
- Pool.ModuleDataType.CLASS_OR_RESOURCE,
+ ModuleEntry.Type.CLASS_OR_RESOURCE,
new ByteArrayInputStream(bytes), bytes.length);
if (!out.contains(ndata)) {
out.add(ndata);
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java
index b8b7aa46cc1..3083c19d2ba 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java
@@ -34,6 +34,7 @@ import java.util.IllformedLocaleException;
import java.util.Locale;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Pattern;
@@ -44,9 +45,10 @@ import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.tools.jlink.internal.ResourcePrevisitor;
import jdk.tools.jlink.internal.StringTable;
import jdk.tools.jlink.internal.Utils;
+import jdk.tools.jlink.plugin.LinkModule;
+import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleDataType;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
/**
@@ -112,19 +114,19 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
}
@Override
- public void visit(Pool in, Pool out) {
- in.visit((resource) -> {
+ public void visit(ModulePool in, ModulePool out) {
+ in.transformAndCopy((resource) -> {
if (resource.getModule().equals(MODULENAME)) {
String path = resource.getPath();
resource = predicate.test(path) ? resource: null;
if (resource != null &&
- resource.getType().equals(ModuleDataType.CLASS_OR_RESOURCE)) {
+ resource.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
byte[] bytes = resource.getBytes();
ClassReader cr = new ClassReader(bytes);
if (Arrays.stream(cr.getInterfaces())
.anyMatch(i -> i.contains(METAINFONAME)) &&
stripUnsupportedLocales(bytes, cr)) {
- resource = new Pool.ModuleData(MODULENAME, path,
+ resource = ModuleEntry.create(MODULENAME, path,
resource.getType(),
new ByteArrayInputStream(bytes), bytes.length);
}
@@ -135,9 +137,9 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.FILTER);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
}
@@ -172,12 +174,13 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
}
@Override
- public void previsit(Pool resources, StringTable strings) {
+ public void previsit(ModulePool resources, StringTable strings) {
final Pattern p = Pattern.compile(".*((Data_)|(Names_))(?.*)\\.class");
- Pool.Module module = resources.getModule(MODULENAME);
+ Optional optMod = resources.findModule(MODULENAME);
// jdk.localedata module validation
- if (module != null) {
+ if (optMod.isPresent()) {
+ LinkModule module = optMod.get();
Set packages = module.getAllPackages();
if (!packages.containsAll(LOCALEDATA_PACKAGES)) {
throw new PluginException(PluginsResourceBundle.getMessage(NAME + ".missingpackages") +
@@ -186,7 +189,7 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
.collect(Collectors.joining(",\n\t")));
}
- available = Stream.concat(module.getContent().stream()
+ available = Stream.concat(module.entries()
.map(md -> p.matcher(md.getPath()))
.filter(m -> m.matches())
.map(m -> m.group("tag").replaceAll("_", "-")),
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OptimizationPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OptimizationPlugin.java
index 4f8e5eade53..9632cdf9b95 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OptimizationPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OptimizationPlugin.java
@@ -24,7 +24,6 @@
*/
package jdk.tools.jlink.internal.plugins;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -287,9 +286,9 @@ public final class OptimizationPlugin extends AsmPlugin {
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.TRANSFORMER);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java
index 8fb124dd775..5060bf5c519 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java
@@ -36,9 +36,8 @@ import java.util.Map;
import java.util.Set;
import java.util.function.ToIntFunction;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
-import jdk.tools.jlink.plugin.Pool.ModuleDataType;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.internal.Utils;
@@ -62,15 +61,15 @@ public final class OrderResourcesPlugin implements TransformerPlugin {
}
static class SortWrapper {
- private final ModuleData resource;
+ private final ModuleEntry resource;
private final int ordinal;
- SortWrapper(ModuleData resource, int ordinal) {
+ SortWrapper(ModuleEntry resource, int ordinal) {
this.resource = resource;
this.ordinal = ordinal;
}
- ModuleData getResource() {
+ ModuleEntry getResource() {
return resource;
}
@@ -95,7 +94,7 @@ public final class OrderResourcesPlugin implements TransformerPlugin {
return path;
}
- private int getOrdinal(ModuleData resource) {
+ private int getOrdinal(ModuleEntry resource) {
String path = resource.getPath();
Integer value = orderedPaths.get(stripModule(path));
@@ -126,23 +125,23 @@ public final class OrderResourcesPlugin implements TransformerPlugin {
}
@Override
- public void visit(Pool in, Pool out) {
- in.getContent().stream()
+ public void visit(ModulePool in, ModulePool out) {
+ in.entries()
.filter(resource -> resource.getType()
- .equals(ModuleDataType.CLASS_OR_RESOURCE))
+ .equals(ModuleEntry.Type.CLASS_OR_RESOURCE))
.map((resource) -> new SortWrapper(resource, getOrdinal(resource)))
.sorted(OrderResourcesPlugin::compare)
.forEach((wrapper) -> out.add(wrapper.getResource()));
- in.getContent().stream()
+ in.entries()
.filter(other -> !other.getType()
- .equals(ModuleDataType.CLASS_OR_RESOURCE))
+ .equals(ModuleEntry.Type.CLASS_OR_RESOURCE))
.forEach((other) -> out.add(other));
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.SORTER);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.SORTER);
return Collections.unmodifiableSet(set);
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java
index bbc7428a41e..579aace7e0a 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java
@@ -24,34 +24,33 @@
*/
package jdk.tools.jlink.internal.plugins;
-import java.lang.module.ModuleDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.EnumSet;
-import java.util.List;
+import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import java.util.Properties;
-
+import java.util.Set;
+import java.util.function.Function;
import jdk.tools.jlink.internal.Utils;
-import jdk.tools.jlink.plugin.ExecutableImage;
-import jdk.tools.jlink.plugin.PluginContext;
-import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.PostProcessorPlugin;
+import jdk.tools.jlink.plugin.ModulePool;
+import jdk.tools.jlink.plugin.Plugin.Category;
+import jdk.tools.jlink.plugin.Plugin.State;
+import jdk.tools.jlink.plugin.TransformerPlugin;
/**
* This plugin adds/deletes information for 'release' file.
*/
-public final class ReleaseInfoPlugin implements PostProcessorPlugin {
+public final class ReleaseInfoPlugin implements TransformerPlugin {
// option name
public static final String NAME = "release-info";
public static final String KEYS = "keys";
+ private final Map release = new HashMap<>();
@Override
- public Set getType() {
- return Collections.singleton(CATEGORY.PROCESSOR);
+ public Set getType() {
+ return Collections.singleton(Category.METAINFO_ADDER);
}
@Override
@@ -65,8 +64,8 @@ public final class ReleaseInfoPlugin implements PostProcessorPlugin {
}
@Override
- public Set getState() {
- return EnumSet.of(STATE.FUNCTIONAL);
+ public Set getState() {
+ return EnumSet.of(State.FUNCTIONAL);
}
@Override
@@ -80,49 +79,49 @@ public final class ReleaseInfoPlugin implements PostProcessorPlugin {
}
@Override
- public void configure(Map config, PluginContext ctx) {
- Properties release = ctx != null? ctx.getReleaseProperties() : null;
- if (release != null) {
- String operation = config.get(NAME);
- switch (operation) {
- case "add": {
- // leave it to open-ended! source, java_version, java_full_version
- // can be passed via this option like:
- //
- // --release-info add:build_type=fastdebug,source=openjdk,java_version=9
- // and put whatever value that was passed in command line.
+ public void configure(Map config) {
+ String operation = config.get(NAME);
+ switch (operation) {
+ case "add": {
+ // leave it to open-ended! source, java_version, java_full_version
+ // can be passed via this option like:
+ //
+ // --release-info add:build_type=fastdebug,source=openjdk,java_version=9
+ // and put whatever value that was passed in command line.
- config.keySet().stream().
- filter(s -> !NAME.equals(s)).
- forEach(s -> release.put(s, config.get(s)));
- }
- break;
-
- case "del": {
- // --release-info del:keys=openjdk,java_version
- String[] keys = Utils.listParser.apply(config.get(KEYS));
- for (String k : keys) {
- release.remove(k);
- }
- }
- break;
-
- default: {
- // --release-info
- try (FileInputStream fis = new FileInputStream(operation)) {
- release.load(fis);
- } catch (IOException exp) {
- throw new RuntimeException(exp);
- }
- }
- break;
+ config.keySet().stream().
+ filter(s -> !NAME.equals(s)).
+ forEach(s -> release.put(s, config.get(s)));
}
+ break;
+
+ case "del": {
+ // --release-info del:keys=openjdk,java_version
+ String[] keys = Utils.listParser.apply(config.get(KEYS));
+ for (String k : keys) {
+ release.remove(k);
+ }
+ }
+ break;
+
+ default: {
+ // --release-info
+ Properties props = new Properties();
+ try (FileInputStream fis = new FileInputStream(operation)) {
+ props.load(fis);
+ } catch (IOException exp) {
+ throw new RuntimeException(exp);
+ }
+ props.forEach((k, v) -> release.put(k.toString(), v.toString()));
+ }
+ break;
}
}
@Override
- public List process(ExecutableImage image) {
- // Nothing to do! Release info copied already during configure!
- return Collections.emptyList();
+ public void visit(ModulePool in, ModulePool out) {
+ in.transformAndCopy(Function.identity(), out);
+ out.getReleaseProperties().putAll(in.getReleaseProperties());
+ out.getReleaseProperties().putAll(release);
}
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StringSharingPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StringSharingPlugin.java
index a4aa8f9d5ca..b3a1e7cf3cf 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StringSharingPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StringSharingPlugin.java
@@ -56,11 +56,11 @@ import java.util.stream.Collectors;
import jdk.internal.jimage.decompressor.CompressIndexes;
import jdk.internal.jimage.decompressor.SignatureParser;
import jdk.internal.jimage.decompressor.StringSharingDecompressor;
-import jdk.tools.jlink.internal.PoolImpl;
+import jdk.tools.jlink.internal.ModulePoolImpl;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.internal.ResourcePrevisitor;
import jdk.tools.jlink.internal.StringTable;
import jdk.tools.jlink.internal.Utils;
@@ -228,7 +228,7 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
}
}
- public byte[] transform(ModuleData resource, Pool out,
+ public byte[] transform(ModuleEntry resource, ModulePool out,
StringTable strings) throws IOException, Exception {
byte[] content = resource.getBytes();
ClassFile cf;
@@ -243,7 +243,7 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
}
@SuppressWarnings("fallthrough")
- private byte[] optimize(ModuleData resource, Pool resources,
+ private byte[] optimize(ModuleEntry resource, ModulePool resources,
StringTable strings,
Set descriptorIndexes, byte[] content) throws Exception {
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(content));
@@ -348,27 +348,27 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.COMPRESSOR);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.COMPRESSOR);
return Collections.unmodifiableSet(set);
}
@Override
- public void visit(Pool in, Pool result) {
+ public void visit(ModulePool in, ModulePool result) {
CompactCPHelper visit = new CompactCPHelper();
- in.visit((resource) -> {
- ModuleData res = resource;
+ in.transformAndCopy((resource) -> {
+ ModuleEntry res = resource;
if (predicate.test(resource.getPath()) && resource.getPath().endsWith(".class")) {
byte[] compressed = null;
try {
- compressed = visit.transform(resource, result, ((PoolImpl) in).getStringTable());
+ compressed = visit.transform(resource, result, ((ModulePoolImpl) in).getStringTable());
} catch (Exception ex) {
throw new PluginException(ex);
}
- res = PoolImpl.newCompressedResource(resource,
+ res = ModulePoolImpl.newCompressedResource(resource,
ByteBuffer.wrap(compressed), getName(), null,
- ((PoolImpl) in).getStringTable(), in.getByteOrder());
+ ((ModulePoolImpl) in).getStringTable(), in.getByteOrder());
}
return res;
}, result);
@@ -405,10 +405,10 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
}
@Override
- public void previsit(Pool resources, StringTable strings) {
+ public void previsit(ModulePool resources, StringTable strings) {
CompactCPHelper preVisit = new CompactCPHelper();
- for (ModuleData resource : resources.getContent()) {
- if (resource.getType().equals(Pool.ModuleDataType.CLASS_OR_RESOURCE)
+ resources.entries().forEach(resource -> {
+ if (resource.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)
&& resource.getPath().endsWith(".class") && predicate.test(resource.getPath())) {
try {
preVisit.transform(resource, null, strings);
@@ -416,6 +416,6 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
throw new PluginException(ex);
}
}
- }
+ });
}
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripDebugPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripDebugPlugin.java
index ae927952226..4e7a036d838 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripDebugPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripDebugPlugin.java
@@ -29,14 +29,12 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
-import jdk.tools.jlink.plugin.Pool.ModuleDataType;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
/**
@@ -61,9 +59,9 @@ public final class StripDebugPlugin implements TransformerPlugin {
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.TRANSFORMER);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@@ -73,11 +71,11 @@ public final class StripDebugPlugin implements TransformerPlugin {
}
@Override
- public void visit(Pool in, Pool out) {
+ public void visit(ModulePool in, ModulePool out) {
//remove *.diz files as well as debug attributes.
- in.visit((resource) -> {
- ModuleData res = resource;
- if (resource.getType().equals(ModuleDataType.CLASS_OR_RESOURCE)) {
+ in.transformAndCopy((resource) -> {
+ ModuleEntry res = resource;
+ if (resource.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
String path = resource.getPath();
if (path.endsWith(".class")) {
if (path.endsWith("module-info.class")) {
@@ -87,7 +85,7 @@ public final class StripDebugPlugin implements TransformerPlugin {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
reader.accept(writer, ClassReader.SKIP_DEBUG);
byte[] content = writer.toByteArray();
- res = Pool.newResource(path, new ByteArrayInputStream(content), content.length);
+ res = ModuleEntry.create(path, new ByteArrayInputStream(content), content.length);
}
}
} else if (predicate.test(res.getPath())) {
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripNativeCommandsPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripNativeCommandsPlugin.java
index dc64582be21..496a4e538d7 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripNativeCommandsPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripNativeCommandsPlugin.java
@@ -26,9 +26,9 @@ package jdk.tools.jlink.internal.plugins;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
-import jdk.tools.jlink.plugin.Pool;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
/**
@@ -45,16 +45,16 @@ public final class StripNativeCommandsPlugin implements TransformerPlugin {
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.FILTER);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
}
@Override
- public void visit(Pool in, Pool out) {
- in.visit((file) -> {
- return file.getType() == Pool.ModuleDataType.NATIVE_CMD ? null : file;
+ public void visit(ModulePool in, ModulePool out) {
+ in.transformAndCopy((file) -> {
+ return file.getType() == ModuleEntry.Type.NATIVE_CMD ? null : file;
}, out);
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModuleDescriptorPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModuleDescriptorPlugin.java
index f4cba7607ea..b60fecb5d16 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModuleDescriptorPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModuleDescriptorPlugin.java
@@ -36,6 +36,7 @@ import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -50,9 +51,10 @@ import jdk.internal.org.objectweb.asm.Opcodes;
import static jdk.internal.org.objectweb.asm.Opcodes.*;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.internal.plugins.SystemModuleDescriptorPlugin.Builder.*;
+import jdk.tools.jlink.plugin.ModuleEntry;
/**
* Jlink plugin to reconstitute module descriptors for installed modules.
@@ -81,8 +83,8 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
}
@Override
- public Set getType() {
- return Collections.singleton(CATEGORY.TRANSFORMER);
+ public Set getType() {
+ return Collections.singleton(Category.TRANSFORMER);
}
@Override
@@ -96,9 +98,9 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
}
@Override
- public Set getState() {
- return enabled ? EnumSet.of(STATE.AUTO_ENABLED, STATE.FUNCTIONAL)
- : EnumSet.of(STATE.DISABLED);
+ public Set getState() {
+ return enabled ? EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL)
+ : EnumSet.of(State.DISABLED);
}
@Override
@@ -110,7 +112,7 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
@Override
- public void visit(Pool in, Pool out) {
+ public void visit(ModulePool in, ModulePool out) {
if (!enabled) {
throw new PluginException(NAME + " was set");
}
@@ -119,13 +121,14 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
// generate the byte code to create ModuleDescriptors
// skip parsing module-info.class and skip name check
- for (Pool.Module module : in.getModules()) {
- Pool.ModuleData data = module.get("module-info.class");
- if (data == null) {
+ in.modules().forEach(module -> {
+ Optional optData = module.findEntry("module-info.class");
+ if (! optData.isPresent()) {
// automatic module not supported yet
throw new PluginException("module-info.class not found for " +
module.getName() + " module");
}
+ ModuleEntry data = optData.get();
assert module.getName().equals(data.getModule());
try {
ByteArrayInputStream bain = new ByteArrayInputStream(data.getBytes());
@@ -141,7 +144,7 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
ModuleInfoRewriter minfoWriter =
new ModuleInfoRewriter(bain, mbuilder.conceals());
// replace with the overridden version
- data = new Pool.ModuleData(data.getModule(),
+ data = ModuleEntry.create(data.getModule(),
data.getPath(),
data.getType(),
minfoWriter.stream(),
@@ -151,19 +154,17 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
} catch (IOException e) {
throw new PluginException(e);
}
-
- }
+ });
// Generate the new class
ClassWriter cwriter = builder.build();
- for (Pool.ModuleData data : in.getContent()) {
+ in.entries().forEach(data -> {
if (data.getPath().endsWith("module-info.class"))
- continue;
-
+ return;
if (builder.isOverriddenClass(data.getPath())) {
byte[] bytes = cwriter.toByteArray();
- Pool.ModuleData ndata =
- new Pool.ModuleData(data.getModule(),
+ ModuleEntry ndata =
+ ModuleEntry.create(data.getModule(),
data.getPath(),
data.getType(),
new ByteArrayInputStream(bytes),
@@ -172,7 +173,7 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
} else {
out.add(data);
}
- }
+ });
}
/*
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ZipPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ZipPlugin.java
index df66e300f5c..d3dd7bff210 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ZipPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ZipPlugin.java
@@ -34,10 +34,9 @@ import java.util.Set;
import java.util.function.Predicate;
import java.util.zip.Deflater;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.internal.PoolImpl;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
-import jdk.tools.jlink.plugin.Pool.ModuleDataType;
+import jdk.tools.jlink.internal.ModulePoolImpl;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.internal.Utils;
@@ -68,9 +67,9 @@ public final class ZipPlugin implements TransformerPlugin {
}
@Override
- public Set getType() {
- Set set = new HashSet<>();
- set.add(CATEGORY.COMPRESSOR);
+ public Set getType() {
+ Set set = new HashSet<>();
+ set.add(Category.COMPRESSOR);
return Collections.unmodifiableSet(set);
}
@@ -124,16 +123,16 @@ public final class ZipPlugin implements TransformerPlugin {
}
@Override
- public void visit(Pool in, Pool out) {
- in.visit((resource) -> {
- ModuleData res = resource;
- if (resource.getType().equals(ModuleDataType.CLASS_OR_RESOURCE)
+ public void visit(ModulePool in, ModulePool out) {
+ in.transformAndCopy((resource) -> {
+ ModuleEntry res = resource;
+ if (resource.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)
&& predicate.test(resource.getPath())) {
byte[] compressed;
compressed = compress(resource.getBytes());
- res = PoolImpl.newCompressedResource(resource,
+ res = ModulePoolImpl.newCompressedResource(resource,
ByteBuffer.wrap(compressed), getName(), null,
- ((PoolImpl) in).getStringTable(), in.getByteOrder());
+ ((ModulePoolImpl) in).getStringTable(), in.getByteOrder());
}
return res;
}, out);
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPlugin.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPlugin.java
index 9902959d059..52712172d5e 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPlugin.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPlugin.java
@@ -26,9 +26,9 @@ package jdk.tools.jlink.internal.plugins.asm;
import java.util.Objects;
import jdk.tools.jlink.plugin.TransformerPlugin;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
-import jdk.tools.jlink.internal.PoolImpl;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.ModulePool;
+import jdk.tools.jlink.internal.ModulePoolImpl;
/**
* Extend this class to develop your own plugin in order to transform jimage
@@ -41,17 +41,17 @@ public abstract class AsmPlugin implements TransformerPlugin {
}
@Override
- public void visit(Pool allContent, Pool outResources) {
+ public void visit(ModulePool allContent, ModulePool outResources) {
Objects.requireNonNull(allContent);
Objects.requireNonNull(outResources);
- PoolImpl resources = new PoolImpl(allContent.getByteOrder());
- for(ModuleData md : allContent.getContent()) {
- if(md.getType().equals(Pool.ModuleDataType.CLASS_OR_RESOURCE)) {
+ ModulePoolImpl resources = new ModulePoolImpl(allContent.getByteOrder());
+ allContent.entries().forEach(md -> {
+ if(md.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
resources.add(md);
} else {
outResources.add(md);
}
- }
+ });
AsmPools pools = new AsmPools(resources);
visit(pools);
pools.fillOutputResources(outResources);
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPool.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPool.java
index 9184bb86257..aa5c1cb5ef5 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPool.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPool.java
@@ -24,13 +24,12 @@
*/
package jdk.tools.jlink.internal.plugins.asm;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;
-import jdk.tools.jlink.plugin.Pool;
+import jdk.tools.jlink.plugin.ModuleEntry;
+import jdk.tools.jlink.plugin.ModulePool;
/**
* A pool of ClassReader and other resource files.
@@ -138,14 +137,14 @@ public interface AsmPool {
* @return The ClassReader or null if the class is not found.
* @throws jdk.tools.jlink.plugin.PluginException
*/
- public ClassReader getClassReader(Pool.ModuleData res);
+ public ClassReader getClassReader(ModuleEntry res);
/**
* Returns all the classes contained in the writable pool.
*
* @return The collection of classes.
*/
- public Collection getClasses();
+ public Collection getClasses();
}
/**
@@ -185,14 +184,14 @@ public interface AsmPool {
* @param res The java resource
* @return The Resource or null if the resource is not found.
*/
- public ResourceFile getResourceFile(Pool.ModuleData res);
+ public ResourceFile getResourceFile(ModuleEntry res);
/**
* Returns all the resources contained in the writable pool.
*
* @return The array of resources.
*/
- public Collection getResourceFiles();
+ public Collection getResourceFiles();
}
/**
@@ -206,7 +205,7 @@ public interface AsmPool {
* @return The resource paths ordered in the way to use for storage in the jimage.
* @throws jdk.tools.jlink.plugin.PluginException
*/
- public List sort(Pool resources);
+ public List sort(ModulePool resources);
}
/**
@@ -237,7 +236,7 @@ public interface AsmPool {
*
* @return The classes.
*/
- public Collection getClasses();
+ public Collection getClasses();
/**
* Returns the resources contained in the pool. Resources are all the file
@@ -245,7 +244,7 @@ public interface AsmPool {
*
* @return The array of resource files.
*/
- public Collection getResourceFiles();
+ public Collection getResourceFiles();
/**
* Retrieves a resource based on the binary name. This name doesn't contain
@@ -266,7 +265,7 @@ public interface AsmPool {
* @param res The resource
* @return The resource file or null if it doesn't exist.
*/
- public ResourceFile getResourceFile(Pool.ModuleData res);
+ public ResourceFile getResourceFile(ModuleEntry res);
/**
* Retrieve a ClassReader from the pool.
@@ -284,7 +283,7 @@ public interface AsmPool {
* @return A reader or null if the class is unknown
* @throws jdk.tools.jlink.plugin.PluginException
*/
- public ClassReader getClassReader(Pool.ModuleData res);
+ public ClassReader getClassReader(ModuleEntry res);
/**
* To visit the set of ClassReaders.
@@ -310,6 +309,6 @@ public interface AsmPool {
* @param output The pool used to fill the jimage.
* @throws jdk.tools.jlink.plugin.PluginException
*/
- public void fillOutputResources(Pool output);
+ public void fillOutputResources(ModulePool output);
}
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPoolImpl.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPoolImpl.java
index cb838d11efa..20c17c85b7b 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPoolImpl.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPoolImpl.java
@@ -41,15 +41,14 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
-import java.util.Optional;
import java.util.Set;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.tools.jlink.internal.ImageFileCreator;
-import jdk.tools.jlink.internal.PoolImpl;
+import jdk.tools.jlink.internal.ModulePoolImpl;
+import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
+import jdk.tools.jlink.plugin.ModulePool;
/**
* A pool of ClassReader and other resource files. This class allows to
@@ -94,7 +93,7 @@ final class AsmPoolImpl implements AsmModulePool {
}
byte[] content = writer.toByteArray();
- ModuleData res = Pool.newResource(path,
+ ModuleEntry res = ModuleEntry.create(path,
new ByteArrayInputStream(content), content.length);
transformedClasses.put(className, res);
}
@@ -108,7 +107,7 @@ final class AsmPoolImpl implements AsmModulePool {
public void forgetClass(String className) {
Objects.requireNonNull(className);
// do we have a resource?
- ModuleData res = transformedClasses.get(className);
+ ModuleEntry res = transformedClasses.get(className);
if (res == null) {
res = inputClasses.get(className);
if (res == null) {
@@ -130,7 +129,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public ClassReader getClassReader(String binaryName) {
Objects.requireNonNull(binaryName);
- ModuleData res = transformedClasses.get(binaryName);
+ ModuleEntry res = transformedClasses.get(binaryName);
ClassReader reader = null;
if (res != null) {
reader = getClassReader(res);
@@ -144,16 +143,16 @@ final class AsmPoolImpl implements AsmModulePool {
* @return The array of transformed classes.
*/
@Override
- public Collection getClasses() {
- List classes = new ArrayList<>();
- for (Entry entry : transformedClasses.entrySet()) {
+ public Collection getClasses() {
+ List classes = new ArrayList<>();
+ for (Entry entry : transformedClasses.entrySet()) {
classes.add(entry.getValue());
}
return classes;
}
@Override
- public ClassReader getClassReader(ModuleData res) {
+ public ClassReader getClassReader(ModuleEntry res) {
return newClassReader(res.getBytes());
}
}
@@ -176,7 +175,7 @@ final class AsmPoolImpl implements AsmModulePool {
public void addResourceFile(ResourceFile resFile) {
Objects.requireNonNull(resFile);
String path = toResourceNamePath(resFile.getPath());
- ModuleData res = Pool.newResource(path, resFile.getContent());
+ ModuleEntry res = ModuleEntry.create(path, resFile.getContent());
transformedResources.put(resFile.getPath(), res);
}
@@ -191,7 +190,7 @@ final class AsmPoolImpl implements AsmModulePool {
Objects.requireNonNull(resourceName);
String path = toResourceNamePath(resourceName);
// do we have a resource?
- ModuleData res = transformedResources.get(resourceName);
+ ModuleEntry res = transformedResources.get(resourceName);
if (res == null) {
res = inputResources.get(resourceName);
if (res == null) {
@@ -212,7 +211,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public ResourceFile getResourceFile(String name) {
Objects.requireNonNull(name);
- ModuleData res = transformedResources.get(name);
+ ModuleEntry res = transformedResources.get(name);
ResourceFile resFile = null;
if (res != null) {
resFile = getResourceFile(res);
@@ -226,24 +225,24 @@ final class AsmPoolImpl implements AsmModulePool {
* @return The array of transformed classes.
*/
@Override
- public Collection getResourceFiles() {
- List resources = new ArrayList<>();
- for (Entry entry : transformedResources.entrySet()) {
+ public Collection getResourceFiles() {
+ List resources = new ArrayList<>();
+ for (Entry entry : transformedResources.entrySet()) {
resources.add(entry.getValue());
}
return resources;
}
@Override
- public ResourceFile getResourceFile(ModuleData res) {
+ public ResourceFile getResourceFile(ModuleEntry res) {
return new ResourceFile(toJavaBinaryResourceName(res.getPath()),
res.getBytes());
}
}
- private final Pool jimageResources;
- private final Map inputClasses;
- private final Map inputResources;
+ private final ModulePool jimageResources;
+ private final Map inputClasses;
+ private final Map inputResources;
private final Map inputClassPackageMapping;
private final Map inputOtherPackageMapping;
@@ -254,9 +253,9 @@ final class AsmPoolImpl implements AsmModulePool {
private Sorter sorter;
- private final Map transformedClasses
+ private final Map transformedClasses
= new LinkedHashMap<>();
- private final Map transformedResources
+ private final Map transformedResources
= new LinkedHashMap<>();
private final List forgetResources = new ArrayList<>();
private final Map newPackageMapping = new HashMap<>();
@@ -274,7 +273,7 @@ final class AsmPoolImpl implements AsmModulePool {
* @param pools The resource pools.
* @param descriptor The module descriptor.
*/
- AsmPoolImpl(Pool inputResources, String moduleName,
+ AsmPoolImpl(ModulePool inputResources, String moduleName,
AsmPools pools,
ModuleDescriptor descriptor) {
Objects.requireNonNull(inputResources);
@@ -285,11 +284,11 @@ final class AsmPoolImpl implements AsmModulePool {
this.moduleName = moduleName;
this.pools = pools;
this.descriptor = descriptor;
- Map classes = new LinkedHashMap<>();
- Map resources = new LinkedHashMap<>();
+ Map classes = new LinkedHashMap<>();
+ Map resources = new LinkedHashMap<>();
Map packageClassToModule = new HashMap<>();
Map packageOtherToModule = new HashMap<>();
- for (ModuleData res : inputResources.getContent()) {
+ inputResources.entries().forEach(res -> {
if (res.getPath().endsWith(".class")) {
classes.put(toJavaBinaryClassName(res.getPath()), res);
} else {
@@ -305,7 +304,7 @@ final class AsmPoolImpl implements AsmModulePool {
packageOtherToModule.put(split[1], res.getModule());
}
}
- }
+ });
this.inputClasses = Collections.unmodifiableMap(classes);
this.inputResources = Collections.unmodifiableMap(resources);
@@ -356,7 +355,7 @@ final class AsmPoolImpl implements AsmModulePool {
* @return The array of classes.
*/
@Override
- public Collection getClasses() {
+ public Collection getClasses() {
return inputClasses.values();
}
@@ -367,7 +366,7 @@ final class AsmPoolImpl implements AsmModulePool {
* @return The array of classes.
*/
@Override
- public Collection getResourceFiles() {
+ public Collection getResourceFiles() {
return inputResources.values();
}
@@ -385,7 +384,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public ResourceFile getResourceFile(String binaryName) {
Objects.requireNonNull(binaryName);
- ModuleData res = inputResources.get(binaryName);
+ ModuleEntry res = inputResources.get(binaryName);
ResourceFile resFile = null;
if (res != null) {
resFile = getResourceFile(res);
@@ -402,7 +401,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public ClassReader getClassReader(String binaryName) {
Objects.requireNonNull(binaryName);
- ModuleData res = inputClasses.get(binaryName);
+ ModuleEntry res = inputClasses.get(binaryName);
ClassReader reader = null;
if (res != null) {
reader = getClassReader(res);
@@ -411,13 +410,13 @@ final class AsmPoolImpl implements AsmModulePool {
}
@Override
- public ResourceFile getResourceFile(ModuleData res) {
+ public ResourceFile getResourceFile(ModuleEntry res) {
return new ResourceFile(toJavaBinaryResourceName(res.getPath()),
res.getBytes());
}
@Override
- public ClassReader getClassReader(ModuleData res) {
+ public ClassReader getClassReader(ModuleEntry res) {
return newClassReader(res.getBytes());
}
@@ -505,7 +504,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public void visitClassReaders(ClassReaderVisitor visitor) {
Objects.requireNonNull(visitor);
- for (ModuleData res : getClasses()) {
+ for (ModuleEntry res : getClasses()) {
ClassReader reader = newClassReader(res.getBytes());
ClassWriter writer = visitor.visit(reader);
if (writer != null) {
@@ -523,7 +522,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public void visitResourceFiles(ResourceFileVisitor visitor) {
Objects.requireNonNull(visitor);
- for (ModuleData resource : getResourceFiles()) {
+ for (ModuleEntry resource : getResourceFiles()) {
ResourceFile resFile
= new ResourceFile(toJavaBinaryResourceName(resource.getPath()),
resource.getBytes());
@@ -540,18 +539,18 @@ final class AsmPoolImpl implements AsmModulePool {
* been set, it is used to sort the returned resources. *
*/
@Override
- public void fillOutputResources(Pool outputResources) {
+ public void fillOutputResources(ModulePool outputResources) {
List added = new ArrayList<>();
// If the sorter is null, use the input order.
// New resources are added at the end
// First input classes that have not been removed
- Pool output = new PoolImpl(outputResources.getByteOrder(),
- ((PoolImpl)outputResources).getStringTable());
- for (ModuleData inResource : jimageResources.getContent()) {
+ ModulePool output = new ModulePoolImpl(outputResources.getByteOrder(),
+ ((ModulePoolImpl)outputResources).getStringTable());
+ jimageResources.entries().forEach(inResource -> {
if (!forgetResources.contains(inResource.getPath())) {
- ModuleData resource = inResource;
+ ModuleEntry resource = inResource;
// Do we have a transformed class with the same name?
- ModuleData res = transformedResources.
+ ModuleEntry res = transformedResources.
get(toJavaBinaryResourceName(inResource.getPath()));
if (res != null) {
resource = res;
@@ -565,10 +564,10 @@ final class AsmPoolImpl implements AsmModulePool {
output.add(resource);
added.add(resource.getPath());
}
- }
+ });
// Then new resources
- for (Map.Entry entry : transformedResources.entrySet()) {
- ModuleData resource = entry.getValue();
+ for (Map.Entry entry : transformedResources.entrySet()) {
+ ModuleEntry resource = entry.getValue();
if (!forgetResources.contains(resource.getPath())) {
if (!added.contains(resource.getPath())) {
output.add(resource);
@@ -576,8 +575,8 @@ final class AsmPoolImpl implements AsmModulePool {
}
}
// And new classes
- for (Map.Entry entry : transformedClasses.entrySet()) {
- ModuleData resource = entry.getValue();
+ for (Map.Entry entry : transformedClasses.entrySet()) {
+ ModuleEntry resource = entry.getValue();
if (!forgetResources.contains(resource.getPath())) {
if (!added.contains(resource.getPath())) {
output.add(resource);
diff --git a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPools.java b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPools.java
index bbb2d5403f8..53742ee5ad7 100644
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPools.java
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/asm/AsmPools.java
@@ -41,11 +41,11 @@ import java.util.Objects;
import java.util.Set;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;
-import jdk.tools.jlink.internal.PoolImpl;
+import jdk.tools.jlink.internal.ModulePoolImpl;
import jdk.tools.jlink.internal.plugins.asm.AsmPool.Sorter;
+import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
-import jdk.tools.jlink.plugin.Pool;
-import jdk.tools.jlink.plugin.Pool.ModuleData;
+import jdk.tools.jlink.plugin.ModulePool;
/**
* A container for pools of ClassReader and other resource files. A pool of all
@@ -97,10 +97,10 @@ public final class AsmPools {
}
@Override
- public Collection getClasses() {
- List all = new ArrayList<>();
+ public Collection getClasses() {
+ List all = new ArrayList<>();
visitAllPools((AsmModulePool pool) -> {
- for (Pool.ModuleData rf : pool.getTransformedClasses().getClasses()) {
+ for (ModuleEntry rf : pool.getTransformedClasses().getClasses()) {
all.add(rf);
}
});
@@ -108,7 +108,7 @@ public final class AsmPools {
}
@Override
- public ClassReader getClassReader(Pool.ModuleData res) {
+ public ClassReader getClassReader(ModuleEntry res) {
return visitPools((AsmModulePool pool) -> {
return pool.getTransformedClasses().getClassReader(res);
});
@@ -140,10 +140,10 @@ public final class AsmPools {
}
@Override
- public Collection getResourceFiles() {
- List all = new ArrayList<>();
+ public Collection