1 /*
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package metaspace.stressHierarchy.common;
24
25 import java.io.BufferedWriter;
26 import java.io.File;
27 import java.io.FileWriter;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.List;
31
32 /**
33 * This class is compiled and invoke due the build to produce
34 * HumongousClass.java. The size of generated file is
35 * too large to store it in the repository.
36 */
37
38 public class HumongousClassGen {
39
40 private static final String CLASS_NAME = "HumongousClass";
41 private static final String PKG_NAME = "metaspace.stressHierarchy.common";
42 private static final String PKG_DIR_NAME = PKG_NAME.replace(".",
43 File.separator);
44 private static final int ITERATIONS = 65300;
45 private static final double MG = (Math.pow(1024, 2));
46 private static final int RECORD_COUNT = ITERATIONS + 10;
47
addFileHeader(List<String> records)48 public static void addFileHeader(List<String> records) {
49 records.add("package " + PKG_NAME + ";\n");
50 records.add("\n");
51 records.add("public class " + CLASS_NAME + " {\n");
52 records.add("\n");
53 }
54
main(String[] args)55 public static void main(String[] args) throws Exception {
56 if (args.length < 1) {
57 System.out.println("Usage: HumongousClassGen "
58 + "<vm-testbase_src_folder>");
59 throw new RuntimeException("Can't generate " + PKG_NAME + "." + CLASS_NAME);
60 }
61
62 List<String> records = new ArrayList<String>(RECORD_COUNT);
63 addFileHeader(records);
64 for (int i = 1; i <= ITERATIONS; i++) {
65 records.add("public long long" + i + ";\n");
66 }
67 records.add("}");
68 writeBuffered(records, (int) (MG * 1), args[0]);
69 }
70
writeBuffered(List<String> records, int bufSize, String srcDir)71 private static void writeBuffered(List<String> records, int bufSize,
72 String srcDir) throws IOException {
73 String path = srcDir + File.separator + PKG_DIR_NAME + File.separator
74 + CLASS_NAME + ".java";
75 System.out.println("Path="+path);
76 File file = new File (path);
77 file.getParentFile().mkdirs();
78 file.createNewFile();
79 long start = System.currentTimeMillis();
80 FileWriter writer = new FileWriter(file);
81 BufferedWriter bufferedWriter = new BufferedWriter(writer, bufSize);
82
83 for (String record: records) {
84 bufferedWriter.write(record);
85 }
86 bufferedWriter.flush();
87 bufferedWriter.close();
88 long end = System.currentTimeMillis();
89 System.out.println((end - start) / 1000f + " seconds");
90 }
91 }
92