8184917: System.initPhase1 does not need to pre-load libzip
Reviewed-by: redestad
--- a/jdk/src/java.base/share/classes/java/lang/System.java Wed Jul 19 08:46:38 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/System.java Wed Jul 19 19:30:08 2017 +0100
@@ -1960,10 +1960,6 @@
setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));
- // Load the zip library now in order to keep java.util.zip.ZipFile
- // from trying to use itself to load this library later.
- loadLibrary("zip");
-
// Setup Java signal handlers for HUP, TERM, and INT (where available).
Terminator.setup();
--- a/jdk/src/java.base/share/classes/java/util/zip/Adler32.java Wed Jul 19 08:46:38 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/util/zip/Adler32.java Wed Jul 19 19:30:08 2017 +0100
@@ -136,4 +136,8 @@
@HotSpotIntrinsicCandidate
private static native int updateByteBuffer(int adler, long addr,
int off, int len);
+
+ static {
+ ZipUtils.loadLibrary();
+ }
}
--- a/jdk/src/java.base/share/classes/java/util/zip/CRC32.java Wed Jul 19 08:46:38 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/util/zip/CRC32.java Wed Jul 19 19:30:08 2017 +0100
@@ -172,4 +172,8 @@
throw new NullPointerException();
}
}
+
+ static {
+ ZipUtils.loadLibrary();
+ }
}
--- a/jdk/src/java.base/share/classes/java/util/zip/Deflater.java Wed Jul 19 08:46:38 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/util/zip/Deflater.java Wed Jul 19 19:30:08 2017 +0100
@@ -154,7 +154,7 @@
public static final int FULL_FLUSH = 3;
static {
- /* Zip library is loaded from System.initializeSystemClass */
+ ZipUtils.loadLibrary();
initIDs();
}
--- a/jdk/src/java.base/share/classes/java/util/zip/Inflater.java Wed Jul 19 08:46:38 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/util/zip/Inflater.java Wed Jul 19 19:30:08 2017 +0100
@@ -85,7 +85,7 @@
private static final byte[] defaultBuf = new byte[0];
static {
- /* Zip library is loaded from System.initializeSystemClass */
+ ZipUtils.loadLibrary();
initIDs();
}
--- a/jdk/src/java.base/share/classes/java/util/zip/ZipUtils.java Wed Jul 19 08:46:38 2017 -0700
+++ b/jdk/src/java.base/share/classes/java/util/zip/ZipUtils.java Wed Jul 19 19:30:08 2017 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, 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
@@ -26,6 +26,8 @@
package java.util.zip;
import java.nio.file.attribute.FileTime;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -245,4 +247,17 @@
// The END header is followed by a variable length comment of size < 64k.
static final long END_MAXLEN = 0xFFFF + ENDHDR;
static final int READBLOCKSZ = 128;
+
+ /**
+ * Loads zip native library, if not already laoded
+ */
+ static void loadLibrary() {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null) {
+ System.loadLibrary("zip");
+ } else {
+ PrivilegedAction<Void> pa = () -> { System.loadLibrary("zip"); return null; };
+ AccessController.doPrivileged(pa);
+ }
+ }
}