equal
deleted
inserted
replaced
48 try { |
48 try { |
49 list.add(new byte[memoryChunk]); |
49 list.add(new byte[memoryChunk]); |
50 used += memoryChunk; |
50 used += memoryChunk; |
51 } catch (OutOfMemoryError e) { |
51 } catch (OutOfMemoryError e) { |
52 list = null; |
52 list = null; |
53 throw new RuntimeException("Unexpected OOME while eating " + targetUsage + " of heap memory."); |
53 throw new RuntimeException("Unexpected OOME '" + e.getMessage() + "' while eating " + targetUsage + " of heap memory."); |
54 } |
54 } |
55 } |
55 } |
56 return list; |
56 return list; |
57 } |
57 } |
58 |
58 |
71 } |
71 } |
72 } |
72 } |
73 |
73 |
74 @Override |
74 @Override |
75 public void eatMetaspaceAndHeap(float targetMemoryUsagePercent) { |
75 public void eatMetaspaceAndHeap(float targetMemoryUsagePercent) { |
|
76 // Metaspace should be filled before Java Heap to prevent unexpected OOME |
|
77 // in the Java Heap while filling Metaspace |
|
78 eatenMetaspace = eatMetaspace(targetMemoryUsagePercent); |
76 eatenMemory = eatHeapMemory(targetMemoryUsagePercent); |
79 eatenMemory = eatHeapMemory(targetMemoryUsagePercent); |
77 eatenMetaspace = eatMetaspace(targetMemoryUsagePercent); |
|
78 } |
80 } |
79 |
81 |
80 private static List<Object> eatMetaspace(float targetUsage) { |
82 private static List<Object> eatMetaspace(float targetUsage) { |
81 List<Object> list = new ArrayList<>(); |
83 List<Object> list = new ArrayList<>(); |
82 final String metaspacePoolName = "Metaspace"; |
84 final String metaspacePoolName = "Metaspace"; |
95 do { |
97 do { |
96 try { |
98 try { |
97 list.add(gp.create(0)); |
99 list.add(gp.create(0)); |
98 } catch (OutOfMemoryError oome) { |
100 } catch (OutOfMemoryError oome) { |
99 list = null; |
101 list = null; |
100 throw new RuntimeException("Unexpected OOME while eating " + targetUsage + " of Metaspace."); |
102 throw new RuntimeException("Unexpected OOME '" + oome.getMessage() + "' while eating " + targetUsage + " of Metaspace."); |
101 } |
103 } |
102 MemoryUsage memoryUsage = metaspacePool.getUsage(); |
104 MemoryUsage memoryUsage = metaspacePool.getUsage(); |
103 currentUsage = (((float) memoryUsage.getUsed()) / memoryUsage.getMax()); |
105 currentUsage = (((float) memoryUsage.getUsed()) / memoryUsage.getMax()); |
104 } while (currentUsage < targetUsage); |
106 } while (currentUsage < targetUsage); |
105 return list; |
107 return list; |