1 /*
2  * @(#)AdaptiveFreeList.java
3  *
4  * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
7  * This code is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License version 2 only, as
9  * published by the Free Software Foundation.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  *
25  */
26 
27 package sun.jvm.hotspot.gc.cms;
28 
29 import java.util.Observable;
30 import java.util.Observer;
31 
32 import sun.jvm.hotspot.debugger.Address;
33 import sun.jvm.hotspot.runtime.VM;
34 import sun.jvm.hotspot.runtime.VMObject;
35 import sun.jvm.hotspot.types.CIntegerField;
36 import sun.jvm.hotspot.types.Type;
37 import sun.jvm.hotspot.types.TypeDataBase;
38 
39 public class AdaptiveFreeList extends VMObject {
40   static {
VM.registerVMInitializedObserver(new Observer() { public void update(Observable o, Object data) { initialize(VM.getVM().getTypeDataBase()); } })41     VM.registerVMInitializedObserver(new Observer() {
42       public void update(Observable o, Object data) {
43         initialize(VM.getVM().getTypeDataBase());
44       }
45     });
46   }
47 
initialize(TypeDataBase db)48   private static synchronized void initialize(TypeDataBase db) {
49     Type type = db.lookupType("AdaptiveFreeList<FreeChunk>");
50     sizeField = type.getCIntegerField("_size");
51     countField = type.getCIntegerField("_count");
52     headerSize = type.getSize();
53   }
54 
55   // Fields
56   private static CIntegerField sizeField;
57   private static CIntegerField countField;
58   private static long          headerSize;
59 
60   //Constructor
AdaptiveFreeList(Address address)61   public AdaptiveFreeList(Address address) {
62     super(address);
63   }
64 
65   // Accessors
size()66   public long size() {
67     return sizeField.getValue(addr);
68   }
69 
count()70   public long count() {
71     return  countField.getValue(addr);
72   }
73 
sizeOf()74   public static long sizeOf() {
75     return headerSize;
76   }
77 }
78