8168073: Speed up URI creation during module bootstrap

Reviewed-by: alanb, mchung, psandoz, chegar
This commit is contained in:
Claes Redestad 2016-10-18 14:22:16 +02:00
parent 16fadae534
commit a424ba8c8d
5 changed files with 49 additions and 24 deletions

View File

@ -44,6 +44,8 @@ import java.util.function.Supplier;
import jdk.internal.jimage.ImageLocation;
import jdk.internal.jimage.ImageReader;
import jdk.internal.jimage.ImageReaderFactory;
import jdk.internal.misc.JavaNetUriAccess;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.module.ModuleHashes;
import jdk.internal.module.ModuleHashes.HashSupplier;
import jdk.internal.module.SystemModules;
@ -71,6 +73,8 @@ class SystemModuleFinder implements ModuleFinder {
// ImageReader used to access all modules in the image
private static final ImageReader imageReader;
private static final JavaNetUriAccess jnua = SharedSecrets.getJavaNetUriAccess();
// the set of modules in the run-time image
private static final Set<ModuleReference> modules;
@ -166,7 +170,8 @@ class SystemModuleFinder implements ModuleFinder {
HashSupplier hash)
{
String mn = md.name();
URI uri = URI.create("jrt:/" + mn);
URI uri = jnua.create("jrt", "/".concat(mn));
Supplier<ModuleReader> readerSupplier = new Supplier<>() {
@Override

View File

@ -37,6 +37,9 @@ import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.CharacterCodingException;
import java.text.Normalizer;
import jdk.internal.loader.URLClassPath;
import jdk.internal.misc.JavaNetUriAccess;
import jdk.internal.misc.SharedSecrets;
import sun.nio.cs.ThreadLocalCoders;
import java.lang.Character; // for javadoc
@ -819,6 +822,25 @@ public final class URI
.parse(false);
}
/**
* Constructs a simple URI consisting of only a scheme and a pre-validated
* path. Provides a fast-path for some internal cases.
*/
URI(String scheme, String path) {
assert validSchemeAndPath(scheme, path);
this.scheme = scheme;
this.path = path;
}
private static boolean validSchemeAndPath(String scheme, String path) {
try {
URI u = new URI(scheme + ":" + path);
return scheme.equals(u.scheme) && path.equals(u.path);
} catch (URISyntaxException e) {
return false;
}
}
/**
* Creates a URI by parsing the given string.
*
@ -3571,5 +3593,13 @@ public final class URI
}
}
static {
SharedSecrets.setJavaNetUriAccess(
new JavaNetUriAccess() {
public URI create(String scheme, String path) {
return new URI(scheme, path);
}
}
);
}
}

View File

@ -51,8 +51,6 @@ import java.util.jar.Manifest;
import jdk.internal.loader.Resource;
import jdk.internal.loader.URLClassPath;
import jdk.internal.misc.JavaNetAccess;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.perf.PerfCounter;
import sun.net.www.ParseUtil;
import sun.security.util.SecurityConstants;
@ -767,13 +765,6 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
}
static {
SharedSecrets.setJavaNetAccess(
new JavaNetAccess() {
public URLClassPath getURLClassPath(URLClassLoader u) {
return u.ucp;
}
}
);
ClassLoader.registerAsParallelCapable();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 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
@ -25,12 +25,11 @@
package jdk.internal.misc;
import java.net.URLClassLoader;
import jdk.internal.loader.URLClassPath;
import java.net.URI;
public interface JavaNetAccess {
public interface JavaNetUriAccess {
/**
* return the URLClassPath belonging to the given loader
* Create a URI of pre-validated scheme and path.
*/
URLClassPath getURLClassPath (URLClassLoader u);
URI create(String scheme, String path);
}

View File

@ -53,10 +53,10 @@ public class SharedSecrets {
private static JavaLangInvokeAccess javaLangInvokeAccess;
private static JavaLangRefAccess javaLangRefAccess;
private static JavaIOAccess javaIOAccess;
private static JavaNetAccess javaNetAccess;
private static JavaNetInetAddressAccess javaNetInetAddressAccess;
private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
private static JavaNetSocketAccess javaNetSocketAccess;
private static JavaNetUriAccess javaNetUriAccess;
private static JavaNioAccess javaNioAccess;
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
private static JavaIOFilePermissionAccess javaIOFilePermissionAccess;
@ -134,14 +134,14 @@ public class SharedSecrets {
return javaLangRefAccess;
}
public static void setJavaNetAccess(JavaNetAccess jna) {
javaNetAccess = jna;
public static void setJavaNetUriAccess(JavaNetUriAccess jnua) {
javaNetUriAccess = jnua;
}
public static JavaNetAccess getJavaNetAccess() {
if (javaNetAccess == null)
unsafe.ensureClassInitialized(java.net.URLClassLoader.class);
return javaNetAccess;
public static JavaNetUriAccess getJavaNetUriAccess() {
if (javaNetUriAccess == null)
unsafe.ensureClassInitialized(java.net.URI.class);
return javaNetUriAccess;
}
public static void setJavaNetInetAddressAccess(JavaNetInetAddressAccess jna) {