src/share/vm/memory/metachunk.hpp

Fri, 25 Jan 2013 15:06:18 -0500

author
acorn
date
Fri, 25 Jan 2013 15:06:18 -0500
changeset 4497
16fb9f942703
parent 4382
e51c9860cf66
child 5007
c23dbf0e8ab7
permissions
-rw-r--r--

6479360: PrintClassHistogram improvements
Summary: jcmd <pid> GC.class_stats (UnlockDiagnosticVMOptions)
Reviewed-by: coleenp, hseigel, sla, acorn
Contributed-by: ioi.lam@oracle.com

     1 /*
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    24 #ifndef SHARE_VM_MEMORY_METACHUNK_HPP
    25 #define SHARE_VM_MEMORY_METACHUNK_HPP
    27 //  Metachunk - Quantum of allocation from a Virtualspace
    28 //    Metachunks are reused (when freed are put on a global freelist) and
    29 //    have no permanent association to a SpaceManager.
    31 //            +--------------+ <- end
    32 //            |              |          --+       ---+
    33 //            |              |            | free     |
    34 //            |              |            |          |
    35 //            |              |            |          | capacity
    36 //            |              |            |          |
    37 //            |              | <- top   --+          |
    38 //            |              |           ---+        |
    39 //            |              |              | used   |
    40 //            |              |              |        |
    41 //            |              |              |        |
    42 //            +--------------+ <- bottom ---+     ---+
    44 class Metachunk VALUE_OBJ_CLASS_SPEC {
    45   // link to support lists of chunks
    46   Metachunk* _next;
    47   Metachunk* _prev;
    49   MetaWord* _bottom;
    50   MetaWord* _end;
    51   MetaWord* _top;
    52   size_t _word_size;
    53   // Used in a guarantee() so included in the Product builds
    54   // even through it is only for debugging.
    55   bool _is_free;
    57   // Metachunks are allocated out of a MetadataVirtualSpace and
    58   // and use some of its space to describe itself (plus alignment
    59   // considerations).  Metadata is allocated in the rest of the chunk.
    60   // This size is the overhead of maintaining the Metachunk within
    61   // the space.
    62   static size_t _overhead;
    64   void set_bottom(MetaWord* v) { _bottom = v; }
    65   void set_end(MetaWord* v) { _end = v; }
    66   void set_top(MetaWord* v) { _top = v; }
    67   void set_word_size(size_t v) { _word_size = v; }
    68  public:
    69 #ifdef ASSERT
    70   Metachunk() : _bottom(NULL), _end(NULL), _top(NULL), _is_free(false),
    71     _next(NULL), _prev(NULL) {}
    72 #else
    73   Metachunk() : _bottom(NULL), _end(NULL), _top(NULL),
    74     _next(NULL), _prev(NULL) {}
    75 #endif
    77   // Used to add a Metachunk to a list of Metachunks
    78   void set_next(Metachunk* v) { _next = v; assert(v != this, "Boom");}
    79   void set_prev(Metachunk* v) { _prev = v; assert(v != this, "Boom");}
    81   MetaWord* allocate(size_t word_size);
    82   static Metachunk* initialize(MetaWord* ptr, size_t word_size);
    84   // Accessors
    85   Metachunk* next() const { return _next; }
    86   Metachunk* prev() const { return _prev; }
    87   MetaWord* bottom() const { return _bottom; }
    88   MetaWord* end() const { return _end; }
    89   MetaWord* top() const { return _top; }
    90   size_t word_size() const { return _word_size; }
    91   size_t size() const volatile { return _word_size; }
    92   void set_size(size_t v) { _word_size = v; }
    93   bool is_free() { return _is_free; }
    94   void set_is_free(bool v) { _is_free = v; }
    95   static size_t overhead() { return _overhead; }
    96   void clear_next()              { set_next(NULL); }
    97   void link_prev(Metachunk* ptr) { set_prev(ptr); }
    98   uintptr_t* end()              { return ((uintptr_t*) this) + size(); }
    99   bool cantCoalesce() const     { return false; }
   100   void link_next(Metachunk* ptr) { set_next(ptr); }
   101   void link_after(Metachunk* ptr){
   102     link_next(ptr);
   103     if (ptr != NULL) ptr->link_prev(this);
   104   }
   106   // Reset top to bottom so chunk can be reused.
   107   void reset_empty() { _top = (_bottom + _overhead); _next = NULL; _prev = NULL; }
   108   bool is_empty() { return _top == (_bottom + _overhead); }
   110   // used (has been allocated)
   111   // free (available for future allocations)
   112   // capacity (total size of chunk)
   113   size_t used_word_size() const;
   114   size_t free_word_size() const;
   115   size_t capacity_word_size()const;
   117   // Debug support
   118 #ifdef ASSERT
   119   void* prev_addr() const { return (void*)&_prev; }
   120   void* next_addr() const { return (void*)&_next; }
   121   void* size_addr() const { return (void*)&_word_size; }
   122 #endif
   123   bool verify_chunk_in_free_list(Metachunk* tc) const { return true; }
   124   bool verify_par_locked() { return true; }
   126   void assert_is_mangled() const {/* Don't check "\*/}
   128   NOT_PRODUCT(void mangle();)
   130   void print_on(outputStream* st) const;
   131   void verify();
   132 };
   133 #endif  // SHARE_VM_MEMORY_METACHUNK_HPP

mercurial