8184917: System.initPhase1 does not need to pre-load libzip

Reviewed-by: redestad
This commit is contained in:
Alan Bateman 2017-07-19 19:30:08 +01:00
parent 037bb0b61f
commit cbfc2c16c2
6 changed files with 26 additions and 7 deletions

View File

@ -1960,10 +1960,6 @@ public final class System {
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();

View File

@ -136,4 +136,8 @@ class Adler32 implements Checksum {
@HotSpotIntrinsicCandidate
private static native int updateByteBuffer(int adler, long addr,
int off, int len);
static {
ZipUtils.loadLibrary();
}
}

View File

@ -172,4 +172,8 @@ class CRC32 implements Checksum {
throw new NullPointerException();
}
}
static {
ZipUtils.loadLibrary();
}
}

View File

@ -154,7 +154,7 @@ class Deflater {
public static final int FULL_FLUSH = 3;
static {
/* Zip library is loaded from System.initializeSystemClass */
ZipUtils.loadLibrary();
initIDs();
}

View File

@ -85,7 +85,7 @@ class Inflater {
private static final byte[] defaultBuf = new byte[0];
static {
/* Zip library is loaded from System.initializeSystemClass */
ZipUtils.loadLibrary();
initIDs();
}

View File

@ -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 @@ class ZipUtils {
// 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);
}
}
}