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