src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ObjectSizeCalculator.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 35407 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ObjectSizeCalculator.java@204abe4d8cbc
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
     1
/*
35407
204abe4d8cbc 8147591: Revisit Collection.toArray(new T[size]) calls in nashorn and dynalink code
mhaupt
parents: 32534
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
     4
 *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    10
 *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    15
 * accompanied this code).
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    16
 *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    20
 *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    23
 * questions.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    24
 */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    25
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    26
package jdk.nashorn.internal.ir.debug;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    27
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    28
import java.lang.reflect.Array;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    29
import java.lang.reflect.Field;
21461
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
    30
import java.lang.reflect.InvocationTargetException;
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
    31
import java.lang.reflect.Method;
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    32
import java.lang.reflect.Modifier;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    33
import java.util.ArrayDeque;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    34
import java.util.ArrayList;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    35
import java.util.Arrays;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    36
import java.util.Deque;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    37
import java.util.IdentityHashMap;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    38
import java.util.LinkedList;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    39
import java.util.List;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    40
import java.util.Map;
28878
838f91fb6e9c 8071989: NashornScriptEngine returns javax.script.ScriptContext instance with insonsistent get/remove methods behavior for undefined attributes
sundar
parents: 25865
diff changeset
    41
import java.util.Objects;
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    42
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    43
/**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    44
 * Contains utility methods for calculating the memory usage of objects. It
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    45
 * only works on the HotSpot JVM, and infers the actual memory layout (32 bit
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    46
 * vs. 64 bit word size, compressed object pointers vs. uncompressed) from
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    47
 * best available indicators. It can reliably detect a 32 bit vs. 64 bit JVM.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    48
 * It can only make an educated guess at whether compressed OOPs are used,
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    49
 * though; specifically, it knows what the JVM's default choice of OOP
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    50
 * compression would be based on HotSpot version and maximum heap sizes, but if
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    51
 * the choice is explicitly overridden with the <tt>-XX:{+|-}UseCompressedOops</tt> command line
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    52
 * switch, it can not detect
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    53
 * this fact and will report incorrect sizes, as it will presume the default JVM
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    54
 * behavior.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    55
 */
25821
fbb51e67d2a7 8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents: 24759
diff changeset
    56
public final class ObjectSizeCalculator {
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    57
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    58
    /**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    59
     * Describes constant memory overheads for various constructs in a JVM implementation.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    60
     */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    61
    public interface MemoryLayoutSpecification {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    62
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    63
        /**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    64
         * Returns the fixed overhead of an array of any type or length in this JVM.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    65
         *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    66
         * @return the fixed overhead of an array.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    67
         */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    68
        int getArrayHeaderSize();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    69
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    70
        /**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    71
         * Returns the fixed overhead of for any {@link Object} subclass in this JVM.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    72
         *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    73
         * @return the fixed overhead of any object.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    74
         */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    75
        int getObjectHeaderSize();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    76
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    77
        /**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    78
         * Returns the quantum field size for a field owned by an object in this JVM.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    79
         *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    80
         * @return the quantum field size for an object.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    81
         */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    82
        int getObjectPadding();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    83
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    84
        /**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    85
         * Returns the fixed size of an object reference in this JVM.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    86
         *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    87
         * @return the size of all object references.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    88
         */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    89
        int getReferenceSize();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    90
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    91
        /**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    92
         * Returns the quantum field size for a field owned by one of an object's ancestor superclasses
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    93
         * in this JVM.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    94
         *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    95
         * @return the quantum field size for a superclass field.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    96
         */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    97
        int getSuperclassFieldPadding();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    98
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
    99
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   100
    private static class CurrentLayout {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   101
        private static final MemoryLayoutSpecification SPEC =
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   102
                getEffectiveMemoryLayoutSpecification();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   103
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   104
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   105
    /**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   106
     * Given an object, returns the total allocated size, in bytes, of the object
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   107
     * and all other objects reachable from it.  Attempts to to detect the current JVM memory layout,
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   108
     * but may fail with {@link UnsupportedOperationException};
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   109
     *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   110
     * @param obj the object; can be null. Passing in a {@link java.lang.Class} object doesn't do
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   111
     *          anything special, it measures the size of all objects
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   112
     *          reachable through it (which will include its class loader, and by
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   113
     *          extension, all other Class objects loaded by
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   114
     *          the same loader, and all the parent class loaders). It doesn't provide the
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   115
     *          size of the static fields in the JVM class that the Class object
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   116
     *          represents.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   117
     * @return the total allocated size of the object and all other objects it
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   118
     *         retains.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   119
     * @throws UnsupportedOperationException if the current vm memory layout cannot be detected.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   120
     */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   121
    public static long getObjectSize(final Object obj) throws UnsupportedOperationException {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   122
        return obj == null ? 0 : new ObjectSizeCalculator(CurrentLayout.SPEC).calculateObjectSize(obj);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   123
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   124
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   125
    // Fixed object header size for arrays.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   126
    private final int arrayHeaderSize;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   127
    // Fixed object header size for non-array objects.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   128
    private final int objectHeaderSize;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   129
    // Padding for the object size - if the object size is not an exact multiple
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   130
    // of this, it is padded to the next multiple.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   131
    private final int objectPadding;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   132
    // Size of reference (pointer) fields.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   133
    private final int referenceSize;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   134
    // Padding for the fields of superclass before fields of subclasses are
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   135
    // added.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   136
    private final int superclassFieldPadding;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   137
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   138
    private final Map<Class<?>, ClassSizeInfo> classSizeInfos = new IdentityHashMap<>();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   139
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   140
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   141
    private final Map<Object, Object> alreadyVisited = new IdentityHashMap<>();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   142
    private final Map<Class<?>, ClassHistogramElement> histogram = new IdentityHashMap<>();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   143
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   144
    private final Deque<Object> pending = new ArrayDeque<>(16 * 1024);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   145
    private long size;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   146
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   147
    /**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   148
     * Creates an object size calculator that can calculate object sizes for a given
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   149
     * {@code memoryLayoutSpecification}.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   150
     *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   151
     * @param memoryLayoutSpecification a description of the JVM memory layout.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   152
     */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   153
    public ObjectSizeCalculator(final MemoryLayoutSpecification memoryLayoutSpecification) {
28878
838f91fb6e9c 8071989: NashornScriptEngine returns javax.script.ScriptContext instance with insonsistent get/remove methods behavior for undefined attributes
sundar
parents: 25865
diff changeset
   154
        Objects.requireNonNull(memoryLayoutSpecification);
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   155
        arrayHeaderSize = memoryLayoutSpecification.getArrayHeaderSize();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   156
        objectHeaderSize = memoryLayoutSpecification.getObjectHeaderSize();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   157
        objectPadding = memoryLayoutSpecification.getObjectPadding();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   158
        referenceSize = memoryLayoutSpecification.getReferenceSize();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   159
        superclassFieldPadding = memoryLayoutSpecification.getSuperclassFieldPadding();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   160
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   161
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   162
    /**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   163
     * Given an object, returns the total allocated size, in bytes, of the object
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   164
     * and all other objects reachable from it.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   165
     *
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   166
     * @param obj the object; can be null. Passing in a {@link java.lang.Class} object doesn't do
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   167
     *          anything special, it measures the size of all objects
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   168
     *          reachable through it (which will include its class loader, and by
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   169
     *          extension, all other Class objects loaded by
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   170
     *          the same loader, and all the parent class loaders). It doesn't provide the
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   171
     *          size of the static fields in the JVM class that the Class object
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   172
     *          represents.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   173
     * @return the total allocated size of the object and all other objects it
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   174
     *         retains.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   175
     */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   176
    public synchronized long calculateObjectSize(final Object obj) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   177
        // Breadth-first traversal instead of naive depth-first with recursive
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   178
        // implementation, so we don't blow the stack traversing long linked lists.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   179
        histogram.clear();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   180
        try {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   181
            for (Object o = obj;;) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   182
                visit(o);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   183
                if (pending.isEmpty()) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   184
                    return size;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   185
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   186
                o = pending.removeFirst();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   187
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   188
        } finally {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   189
            alreadyVisited.clear();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   190
            pending.clear();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   191
            size = 0;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   192
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   193
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   194
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   195
    /**
32534
b3ec7f3b3c2a 8136349: Typos patch for nashorn sources submitted on Sep 10, 2015
sundar
parents: 31549
diff changeset
   196
     * Get the class histogram
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   197
     * @return class histogram element list
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   198
     */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   199
    public List<ClassHistogramElement> getClassHistogram() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   200
        return new ArrayList<>(histogram.values());
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   201
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   202
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   203
    private ClassSizeInfo getClassSizeInfo(final Class<?> clazz) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   204
        ClassSizeInfo csi = classSizeInfos.get(clazz);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   205
        if(csi == null) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   206
            csi = new ClassSizeInfo(clazz);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   207
            classSizeInfos.put(clazz, csi);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   208
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   209
        return csi;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   210
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   211
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   212
    private void visit(final Object obj) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   213
        if (alreadyVisited.containsKey(obj)) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   214
            return;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   215
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   216
        final Class<?> clazz = obj.getClass();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   217
        if (clazz == ArrayElementsVisitor.class) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   218
            ((ArrayElementsVisitor) obj).visit(this);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   219
        } else {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   220
            alreadyVisited.put(obj, obj);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   221
            if (clazz.isArray()) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   222
                visitArray(obj);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   223
            } else {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   224
                getClassSizeInfo(clazz).visit(obj, this);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   225
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   226
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   227
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   228
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   229
    private void visitArray(final Object array) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   230
        final Class<?> arrayClass = array.getClass();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   231
        final Class<?> componentType = arrayClass.getComponentType();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   232
        final int length = Array.getLength(array);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   233
        if (componentType.isPrimitive()) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   234
            increaseByArraySize(arrayClass, length, getPrimitiveFieldSize(componentType));
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   235
        } else {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   236
            increaseByArraySize(arrayClass, length, referenceSize);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   237
            // If we didn't use an ArrayElementsVisitor, we would be enqueueing every
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   238
            // element of the array here instead. For large arrays, it would
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   239
            // tremendously enlarge the queue. In essence, we're compressing it into
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   240
            // a small command object instead. This is different than immediately
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   241
            // visiting the elements, as their visiting is scheduled for the end of
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   242
            // the current queue.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   243
            switch (length) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   244
            case 0: {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   245
                break;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   246
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   247
            case 1: {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   248
                enqueue(Array.get(array, 0));
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   249
                break;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   250
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   251
            default: {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   252
                enqueue(new ArrayElementsVisitor((Object[]) array));
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   253
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   254
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   255
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   256
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   257
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   258
    private void increaseByArraySize(final Class<?> clazz, final int length, final long elementSize) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   259
        increaseSize(clazz, roundTo(arrayHeaderSize + length * elementSize, objectPadding));
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   260
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   261
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   262
    private static class ArrayElementsVisitor {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   263
        private final Object[] array;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   264
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   265
        ArrayElementsVisitor(final Object[] array) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   266
            this.array = array;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   267
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   268
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   269
        public void visit(final ObjectSizeCalculator calc) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   270
            for (final Object elem : array) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   271
                if (elem != null) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   272
                    calc.visit(elem);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   273
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   274
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   275
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   276
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   277
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   278
    void enqueue(final Object obj) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   279
        if (obj != null) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   280
            pending.addLast(obj);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   281
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   282
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   283
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   284
    void increaseSize(final Class<?> clazz, final long objectSize) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   285
        ClassHistogramElement he = histogram.get(clazz);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   286
        if(he == null) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   287
            he = new ClassHistogramElement(clazz);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   288
            histogram.put(clazz, he);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   289
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   290
        he.addInstance(objectSize);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   291
        size += objectSize;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   292
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   293
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   294
    static long roundTo(final long x, final int multiple) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   295
        return ((x + multiple - 1) / multiple) * multiple;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   296
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   297
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   298
    private class ClassSizeInfo {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   299
        // Padded fields + header size
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   300
        private final long objectSize;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   301
        // Only the fields size - used to calculate the subclasses' memory
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   302
        // footprint.
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   303
        private final long fieldsSize;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   304
        private final Field[] referenceFields;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   305
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   306
        public ClassSizeInfo(final Class<?> clazz) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   307
            long newFieldsSize = 0;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   308
            final List<Field> newReferenceFields = new LinkedList<>();
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 21461
diff changeset
   309
            for (final Field f : clazz.getDeclaredFields()) {
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   310
                if (Modifier.isStatic(f.getModifiers())) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   311
                    continue;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   312
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   313
                final Class<?> type = f.getType();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   314
                if (type.isPrimitive()) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   315
                    newFieldsSize += getPrimitiveFieldSize(type);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   316
                } else {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   317
                    f.setAccessible(true);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   318
                    newReferenceFields.add(f);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   319
                    newFieldsSize += referenceSize;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   320
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   321
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   322
            final Class<?> superClass = clazz.getSuperclass();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   323
            if (superClass != null) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   324
                final ClassSizeInfo superClassInfo = getClassSizeInfo(superClass);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   325
                newFieldsSize += roundTo(superClassInfo.fieldsSize, superclassFieldPadding);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   326
                newReferenceFields.addAll(Arrays.asList(superClassInfo.referenceFields));
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   327
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   328
            this.fieldsSize = newFieldsSize;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   329
            this.objectSize = roundTo(objectHeaderSize + newFieldsSize, objectPadding);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   330
            this.referenceFields = newReferenceFields.toArray(
35407
204abe4d8cbc 8147591: Revisit Collection.toArray(new T[size]) calls in nashorn and dynalink code
mhaupt
parents: 32534
diff changeset
   331
                    new Field[0]);
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   332
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   333
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   334
        void visit(final Object obj, final ObjectSizeCalculator calc) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   335
            calc.increaseSize(obj.getClass(), objectSize);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   336
            enqueueReferencedObjects(obj, calc);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   337
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   338
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   339
        public void enqueueReferencedObjects(final Object obj, final ObjectSizeCalculator calc) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 21461
diff changeset
   340
            for (final Field f : referenceFields) {
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   341
                try {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   342
                    calc.enqueue(f.get(obj));
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 21461
diff changeset
   343
                } catch (final IllegalAccessException e) {
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   344
                    final AssertionError ae = new AssertionError(
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   345
                            "Unexpected denial of access to " + f);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   346
                    ae.initCause(e);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   347
                    throw ae;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   348
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   349
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   350
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   351
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   352
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   353
    private static long getPrimitiveFieldSize(final Class<?> type) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   354
        if (type == boolean.class || type == byte.class) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   355
            return 1;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   356
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   357
        if (type == char.class || type == short.class) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   358
            return 2;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   359
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   360
        if (type == int.class || type == float.class) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   361
            return 4;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   362
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   363
        if (type == long.class || type == double.class) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   364
            return 8;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   365
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   366
        throw new AssertionError("Encountered unexpected primitive type " +
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   367
                type.getName());
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   368
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   369
21461
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   370
    // ALERT: java.lang.management is not available in compact 1.  We need
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   371
    // to use reflection to soft link test memory statistics.
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   372
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   373
    static Class<?>  managementFactory    = null;
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   374
    static Class<?>  memoryPoolMXBean     = null;
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   375
    static Class<?>  memoryUsage          = null;
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   376
    static Method    getMemoryPoolMXBeans = null;
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   377
    static Method    getUsage             = null;
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   378
    static Method    getMax               = null;
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   379
    static {
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   380
        try {
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   381
            managementFactory    = Class.forName("java.lang.management.ManagementFactory");
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   382
            memoryPoolMXBean     = Class.forName("java.lang.management.MemoryPoolMXBean");
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   383
            memoryUsage          = Class.forName("java.lang.management.MemoryUsage");
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   384
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   385
            getMemoryPoolMXBeans = managementFactory.getMethod("getMemoryPoolMXBeans");
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   386
            getUsage             = memoryPoolMXBean.getMethod("getUsage");
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   387
            getMax               = memoryUsage.getMethod("getMax");
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   388
        } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   389
            // Pass thru, asserts when attempting to use.
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   390
        }
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   391
    }
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   392
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   393
    /**
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   394
     * Return the current memory usage
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   395
     * @return current memory usage derived from system configuration
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   396
     */
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   397
    public static MemoryLayoutSpecification getEffectiveMemoryLayoutSpecification() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   398
        final String vmName = System.getProperty("java.vm.name");
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   399
        if (vmName == null || !vmName.startsWith("Java HotSpot(TM) ")) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   400
            throw new UnsupportedOperationException(
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   401
                    "ObjectSizeCalculator only supported on HotSpot VM");
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   402
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   403
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   404
        final String dataModel = System.getProperty("sun.arch.data.model");
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   405
        if ("32".equals(dataModel)) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   406
            // Running with 32-bit data model
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   407
            return new MemoryLayoutSpecification() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   408
                @Override public int getArrayHeaderSize() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   409
                    return 12;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   410
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   411
                @Override public int getObjectHeaderSize() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   412
                    return 8;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   413
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   414
                @Override public int getObjectPadding() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   415
                    return 8;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   416
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   417
                @Override public int getReferenceSize() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   418
                    return 4;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   419
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   420
                @Override public int getSuperclassFieldPadding() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   421
                    return 4;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   422
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   423
            };
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   424
        } else if (!"64".equals(dataModel)) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   425
            throw new UnsupportedOperationException("Unrecognized value '" +
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   426
                    dataModel + "' of sun.arch.data.model system property");
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   427
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   428
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   429
        final String strVmVersion = System.getProperty("java.vm.version");
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   430
        final int vmVersion = Integer.parseInt(strVmVersion.substring(0,
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   431
                strVmVersion.indexOf('.')));
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   432
        if (vmVersion >= 17) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   433
            long maxMemory = 0;
21461
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   434
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   435
            /*
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   436
               See ALERT above.  The reflection code below duplicates the following
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   437
               sequence, and avoids hard coding of java.lang.management.
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   438
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   439
               for (MemoryPoolMXBean mp : ManagementFactory.getMemoryPoolMXBeans()) {
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   440
                   maxMemory += mp.getUsage().getMax();
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   441
               }
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   442
            */
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   443
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   444
            if (getMemoryPoolMXBeans == null) {
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   445
                throw new AssertionError("java.lang.management not available in compact 1");
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   446
            }
21461
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   447
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   448
            try {
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   449
                final List<?> memoryPoolMXBeans = (List<?>)getMemoryPoolMXBeans.invoke(managementFactory);
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   450
                for (final Object mp : memoryPoolMXBeans) {
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   451
                    final Object usage = getUsage.invoke(mp);
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   452
                    final Object max = getMax.invoke(usage);
31549
b627094c5649 8130734: Apply transformations found by netbeans Refactor->Inspect and transform menu
sundar
parents: 28878
diff changeset
   453
                    maxMemory += ((Long)max);
21461
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   454
                }
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   455
            } catch (IllegalAccessException |
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   456
                     IllegalArgumentException |
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   457
                     InvocationTargetException ex) {
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   458
                throw new AssertionError("java.lang.management not available in compact 1");
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   459
            }
57b33ebf19db 8027532: nashorn should only use jdk8 apis in the compact1 profile
jlaskey
parents: 17519
diff changeset
   460
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   461
            if (maxMemory < 30L * 1024 * 1024 * 1024) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   462
                // HotSpot 17.0 and above use compressed OOPs below 30GB of RAM total
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   463
                // for all memory pools (yes, including code cache).
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   464
                return new MemoryLayoutSpecification() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   465
                    @Override public int getArrayHeaderSize() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   466
                        return 16;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   467
                    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   468
                    @Override public int getObjectHeaderSize() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   469
                        return 12;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   470
                    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   471
                    @Override public int getObjectPadding() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   472
                        return 8;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   473
                    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   474
                    @Override public int getReferenceSize() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   475
                        return 4;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   476
                    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   477
                    @Override public int getSuperclassFieldPadding() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   478
                        return 4;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   479
                    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   480
                };
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   481
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   482
        }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   483
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   484
        // In other cases, it's a 64-bit uncompressed OOPs object model
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   485
        return new MemoryLayoutSpecification() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   486
            @Override public int getArrayHeaderSize() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   487
                return 24;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   488
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   489
            @Override public int getObjectHeaderSize() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   490
                return 16;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   491
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   492
            @Override public int getObjectPadding() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   493
                return 8;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   494
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   495
            @Override public int getReferenceSize() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   496
                return 8;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   497
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   498
            @Override public int getSuperclassFieldPadding() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   499
                return 8;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   500
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   501
        };
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   502
    }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents:
diff changeset
   503
}