src/jdk.internal.vm.compiler/share/classes/org.graalvm.util/src/org/graalvm/util/ObjectSizeEstimate.java
equal
deleted
inserted
replaced
23 package org.graalvm.util; |
23 package org.graalvm.util; |
24 |
24 |
25 import java.lang.reflect.Field; |
25 import java.lang.reflect.Field; |
26 import java.lang.reflect.Modifier; |
26 import java.lang.reflect.Modifier; |
27 import java.util.ArrayList; |
27 import java.util.ArrayList; |
|
28 |
|
29 import org.graalvm.collections.EconomicMap; |
|
30 import org.graalvm.collections.Equivalence; |
28 |
31 |
29 /** |
32 /** |
30 * Calculates approximate estimates of the size of an object graph. |
33 * Calculates approximate estimates of the size of an object graph. |
31 * |
34 * |
32 * The result contains number of object headers {@link #getHeaderCount()}, number of pointers |
35 * The result contains number of object headers {@link #getHeaderCount()}, number of pointers |
191 } else if (type == Double.TYPE) { |
194 } else if (type == Double.TYPE) { |
192 size.recordPrimitiveBytes(Double.BYTES); |
195 size.recordPrimitiveBytes(Double.BYTES); |
193 } else { |
196 } else { |
194 size.recordPointer(); |
197 size.recordPointer(); |
195 if (maxDepth > 1) { |
198 if (maxDepth > 1) { |
196 f.setAccessible(true); |
|
197 try { |
199 try { |
|
200 f.setAccessible(true); |
198 Object inner = f.get(o); |
201 Object inner = f.get(o); |
199 if (inner != null) { |
202 if (inner != null) { |
200 if (depth < maxDepth && !identityHashMap.containsKey(inner)) { |
203 if (depth < maxDepth && !identityHashMap.containsKey(inner)) { |
201 identityHashMap.put(inner, null); |
204 identityHashMap.put(inner, null); |
202 stack.add(inner); |
205 stack.add(inner); |
203 depthStack.add(depth + 1); |
206 depthStack.add(depth + 1); |
204 } |
207 } |
205 } |
208 } |
206 } catch (IllegalArgumentException | IllegalAccessException e) { |
209 } catch (IllegalArgumentException | IllegalAccessException e) { |
207 throw new UnsupportedOperationException("Must have access privileges to traverse object graph"); |
210 throw new UnsupportedOperationException("Must have access privileges to traverse object graph"); |
|
211 } catch (RuntimeException e) { |
|
212 if ("java.lang.reflect.InaccessibleObjectException".equals(e.getClass().getName())) { |
|
213 // This is a newly introduced exception in JDK9 and thus |
|
214 // cannot be declared in the catch clause. |
|
215 throw new UnsupportedOperationException("Target class is not exported to the current module.", e); |
|
216 } else { |
|
217 throw e; |
|
218 } |
208 } |
219 } |
209 } |
220 } |
210 } |
221 } |
211 } |
222 } |
212 } |
223 } |