85 }
86
87 public static void main(String args[]) throws Exception {
88 testWithG1ClassUnloading();
89 testWithoutG1ClassUnloading();
90 }
91
92 public static class AllocateBeyondMetaspaceSize {
93 public static Object dummy;
94
95 public static void main(String [] args) throws Exception {
96 if (args.length != 2) {
97 throw new IllegalArgumentException("Usage: <MetaspaceSize> <YoungGenSize>");
98 }
99
100 WhiteBox wb = WhiteBox.getWhiteBox();
101
102 // Allocate past the MetaspaceSize limit
103 long metaspaceSize = Long.parseLong(args[0]);
104 long allocationBeyondMetaspaceSize = metaspaceSize * 2;
105 long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize);
106
107 long youngGenSize = Long.parseLong(args[1]);
108 triggerYoungGCs(youngGenSize);
109
110 wb.freeMetaspace(null, metaspace, metaspace);
111 }
112
113 public static void triggerYoungGCs(long youngGenSize) {
114 long approxAllocSize = 32 * 1024;
115 long numAllocations = 2 * youngGenSize / approxAllocSize;
116
117 for (long i = 0; i < numAllocations; i++) {
118 dummy = new byte[(int)approxAllocSize];
119 }
120 }
121 }
122 }
123
|
85 }
86
87 public static void main(String args[]) throws Exception {
88 testWithG1ClassUnloading();
89 testWithoutG1ClassUnloading();
90 }
91
92 public static class AllocateBeyondMetaspaceSize {
93 public static Object dummy;
94
95 public static void main(String [] args) throws Exception {
96 if (args.length != 2) {
97 throw new IllegalArgumentException("Usage: <MetaspaceSize> <YoungGenSize>");
98 }
99
100 WhiteBox wb = WhiteBox.getWhiteBox();
101
102 // Allocate past the MetaspaceSize limit
103 long metaspaceSize = Long.parseLong(args[0]);
104 long allocationBeyondMetaspaceSize = metaspaceSize * 2;
105
106 // There is a cap on how large a single metaspace allocation can get. So we may have to allocate in blocks.
107 final long max = wb.maxMetaspaceAllocationSize();
108 while (allocationBeyondMetaspaceSize > 0) {
109 long s = max < allocationBeyondMetaspaceSize ? max : allocationBeyondMetaspaceSize;
110 wb.allocateMetaspace(null, s);
111 allocationBeyondMetaspaceSize -= s;
112 }
113
114 long youngGenSize = Long.parseLong(args[1]);
115 triggerYoungGCs(youngGenSize);
116
117 }
118
119 public static void triggerYoungGCs(long youngGenSize) {
120 long approxAllocSize = 32 * 1024;
121 long numAllocations = 2 * youngGenSize / approxAllocSize;
122
123 for (long i = 0; i < numAllocations; i++) {
124 dummy = new byte[(int)approxAllocSize];
125 }
126 }
127 }
128 }
129
|