• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 package jumbostring;
5 
6 import java.io.IOException;
7 import java.io.PrintStream;
8 import java.nio.file.FileSystems;
9 import java.nio.file.Files;
10 import java.nio.file.Path;
11 import java.nio.file.StandardOpenOption;
12 
13 class JumboString {
main(String[] args)14   public static void main(String[] args) {
15     // Make sure this string sorts after the field names and string values in the StringPoolX.java
16     // files to ensure this is a jumbo string.
17     System.out.println("zzzz - jumbo string");
18   }
19 
20   // Code for generating the StringPoolX.java files.
21   //
22   // We only need to generate two files to get jumbo strings. Each file has 16k static final fields
23   // with values, and both the field name and the value will be in the string pool.
generate()24   public static void generate() throws IOException {
25     int stringsPerFile = (1 << 14);
26     for (int fileNumber = 0; fileNumber < 2; fileNumber++) {
27       Path path = FileSystems.getDefault().getPath("StringPool" + fileNumber + ".java");
28       PrintStream out = new PrintStream(
29           Files.newOutputStream(path, StandardOpenOption.CREATE, StandardOpenOption.APPEND));
30 
31       out.println(
32           "// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file");
33       out.println(
34           "// for details. All rights reserved. Use of this source code is governed by a");
35       out.println("// BSD-style license that can be found in the LICENSE file.");
36       out.println("package jumbostring;");
37       out.println();
38       out.println("class StringPool" + fileNumber + " {");
39 
40       int offset = fileNumber * stringsPerFile;
41       for (int i = offset; i < offset + stringsPerFile; i++) {
42         out.println("  public static final String s" + i + " = \"" + i + "\";");
43       }
44       out.println("}");
45       out.close();
46     }
47   }
48 }
49