diff --git a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/QuarkusEntryPoint.java b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/QuarkusEntryPoint.java index 5c886b3a0f1ce..68f962ff14a7a 100644 --- a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/QuarkusEntryPoint.java +++ b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/QuarkusEntryPoint.java @@ -1,5 +1,6 @@ package io.quarkus.bootstrap.runner; +import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -35,17 +36,18 @@ private static void doRun(Object args) throws IOException, ClassNotFoundExceptio } else if (Boolean.getBoolean("quarkus.launch.rebuild")) { doReaugment(appRoot); } else { - SerializedApplication app = null; - try (InputStream in = Files.newInputStream(appRoot.resolve(QUARKUS_APPLICATION_DAT))) { + SerializedApplication app; + // the magic number here is close to the smallest possible dat file + try (InputStream in = new BufferedInputStream(Files.newInputStream(appRoot.resolve(QUARKUS_APPLICATION_DAT)), + 24_576)) { app = SerializedApplication.read(in, appRoot); + } + try { Thread.currentThread().setContextClassLoader(app.getRunnerClassLoader()); Class mainClass = app.getRunnerClassLoader().loadClass(app.getMainClass()); mainClass.getMethod("main", String[].class).invoke(null, args); - } finally { - if (app != null) { - app.getRunnerClassLoader().close(); - } + app.getRunnerClassLoader().close(); } } } diff --git a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java index 3596baab02ccf..bbfa898f0248c 100644 --- a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java +++ b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java @@ -63,7 +63,7 @@ public static void write(OutputStream outputStream, String mainClass, Path appli data.writeInt(MAGIC); data.writeInt(VERSION); data.writeUTF(mainClass); - data.writeInt(classPath.size()); + data.writeShort(classPath.size()); Map> directlyIndexedResourcesToCPJarIndex = new HashMap<>(); for (int i = 0; i < classPath.size(); i++) { Path jar = classPath.get(i); @@ -79,20 +79,20 @@ public static void write(OutputStream outputStream, String mainClass, Path appli for (Path jar : parentFirst) { collectPackages(jar, parentFirstPackages); } - data.writeInt(parentFirstPackages.size()); + data.writeShort(parentFirstPackages.size()); for (String p : parentFirstPackages) { data.writeUTF(p.replace("/", ".").replace("\\", ".")); } - data.writeInt(nonExistentResources.size()); + data.writeShort(nonExistentResources.size()); for (String nonExistentResource : nonExistentResources) { data.writeUTF(nonExistentResource); } - data.writeInt(directlyIndexedResourcesToCPJarIndex.size()); + data.writeShort(directlyIndexedResourcesToCPJarIndex.size()); for (Map.Entry> entry : directlyIndexedResourcesToCPJarIndex.entrySet()) { data.writeUTF(entry.getKey()); - data.writeInt(entry.getValue().size()); + data.writeShort(entry.getValue().size()); for (Integer index : entry.getValue()) { - data.writeInt(index); + data.writeShort(index); } } data.flush(); @@ -110,7 +110,7 @@ public static SerializedApplication read(InputStream inputStream, Path appRoot) String mainClass = in.readUTF(); Map resourceDirectoryMap = new HashMap<>(); Set parentFirstPackages = new HashSet<>(); - int numPaths = in.readInt(); + int numPaths = in.readUnsignedShort(); ClassLoadingResource[] allClassLoadingResources = new ClassLoadingResource[numPaths]; for (int pathCount = 0; pathCount < numPaths; pathCount++) { String path = in.readUTF(); @@ -122,7 +122,7 @@ public static SerializedApplication read(InputStream inputStream, Path appRoot) } JarResource resource = new JarResource(info, appRoot.resolve(path)); allClassLoadingResources[pathCount] = resource; - int numDirs = in.readInt(); + int numDirs = in.readUnsignedShort(); for (int i = 0; i < numDirs; ++i) { String dir = in.readUTF(); ClassLoadingResource[] existing = resourceDirectoryMap.get(dir); @@ -136,25 +136,25 @@ public static SerializedApplication read(InputStream inputStream, Path appRoot) } } } - int packages = in.readInt(); + int packages = in.readUnsignedShort(); for (int i = 0; i < packages; ++i) { parentFirstPackages.add(in.readUTF()); } Set nonExistentResources = new HashSet<>(); - int nonExistentResourcesSize = in.readInt(); + int nonExistentResourcesSize = in.readUnsignedShort(); for (int i = 0; i < nonExistentResourcesSize; i++) { nonExistentResources.add(in.readUTF()); } // this map is populated correctly because the JarResource entries are added to allClassLoadingResources // in the same order as the classpath was written during the writing of the index Map directlyIndexedResourcesIndexMap = new HashMap<>(); - int directlyIndexedSize = in.readInt(); + int directlyIndexedSize = in.readUnsignedShort(); for (int i = 0; i < directlyIndexedSize; i++) { String resource = in.readUTF(); - int indexesSize = in.readInt(); + int indexesSize = in.readUnsignedShort(); ClassLoadingResource[] matchingResources = new ClassLoadingResource[indexesSize]; for (int j = 0; j < indexesSize; j++) { - matchingResources[j] = allClassLoadingResources[in.readInt()]; + matchingResources[j] = allClassLoadingResources[in.readUnsignedShort()]; } directlyIndexedResourcesIndexMap.put(resource, matchingResources); } @@ -242,7 +242,7 @@ private static List writeJar(DataOutputStream out, Path jar) throws IOEx if (hasDefaultPackage) { dirs.add(""); } - out.writeInt(dirs.size()); + out.writeShort(dirs.size()); for (String i : dirs) { out.writeUTF(i); }