22 *
23 */
24
25 package sun.jvm.hotspot.runtime;
26
27 import java.io.*;
28 import java.util.*;
29 import sun.jvm.hotspot.debugger.*;
30 import sun.jvm.hotspot.oops.*;
31 import sun.jvm.hotspot.types.*;
32
33 /** <P> ThreadLocalAllocBuffer: a descriptor for thread-local storage
34 used by the threads for allocation. </P>
35
36 <P> It is thread-private at any time, but maybe multiplexed over
37 time across multiple threads. </P> */
38
39 public class ThreadLocalAllocBuffer extends VMObject {
40 private static AddressField startField;
41 private static AddressField topField;
42 private static AddressField endField;
43 private static CIntegerField desired_sizeField;
44
45 static {
46 VM.registerVMInitializedObserver(new Observer() {
47 public void update(Observable o, Object data) {
48 initialize(VM.getVM().getTypeDataBase());
49 }
50 });
51 }
52
53 private static synchronized void initialize(TypeDataBase db) {
54 Type type = db.lookupType("ThreadLocalAllocBuffer");
55
56 startField = type.getAddressField("_start");
57 topField = type.getAddressField("_top");
58 endField = type.getAddressField("_end");
59 desired_sizeField = type.getCIntegerField("_desired_size");
60 }
61
62 public ThreadLocalAllocBuffer(Address addr) {
63 super(addr);
64 }
65
66 public Address start() { return startField.getValue(addr); }
67 public Address end() { return endField.getValue(addr); }
68 public Address top() { return topField.getValue(addr); }
69 public Address hardEnd() { return end().addOffsetTo(alignmentReserve()); }
70
71 private long alignmentReserve() {
72 return Oop.alignObjectSize(endReserve());
73 }
74
75 private long endReserve() {
76 long minFillerArraySize = Array.baseOffsetInBytes(BasicType.T_INT);
77 long reserveForAllocationPrefetch = VM.getVM().getReserveForAllocationPrefetch();
78 long heapWordSize = VM.getVM().getHeapWordSize();
79
80 return Math.max(minFillerArraySize, reserveForAllocationPrefetch * heapWordSize);
81 }
82
83 /** Support for iteration over heap -- not sure how this will
84 interact with GC in reflective system, but necessary for the
85 debugging mechanism */
86 public OopHandle startAsOopHandle() {
87 return startField.getOopHandle(addr);
88 }
89
92 debugging mechanism */
93 public OopHandle nextOopHandle(OopHandle handle, long size) {
94 return handle.addOffsetToAsOopHandle(size);
95 }
96
97 // public int size(); // FIXME: must adjust this to be in bytes
98 // public int availableSize(); // FIXME: must adjust this to be in bytes
99 public void print() {
100 printOn(System.out);
101 }
102
103 public boolean contains(Address p) {
104 if (top() == null) {
105 return false;
106 }
107 return (start().lessThanOrEqual(p) && top().greaterThan(p));
108 }
109
110 public void printOn(PrintStream tty) {
111 tty.println(" [" + start() + "," +
112 top() + "," + end() + ",{" + hardEnd() + "})");
113 }
114 }
|
22 *
23 */
24
25 package sun.jvm.hotspot.runtime;
26
27 import java.io.*;
28 import java.util.*;
29 import sun.jvm.hotspot.debugger.*;
30 import sun.jvm.hotspot.oops.*;
31 import sun.jvm.hotspot.types.*;
32
33 /** <P> ThreadLocalAllocBuffer: a descriptor for thread-local storage
34 used by the threads for allocation. </P>
35
36 <P> It is thread-private at any time, but maybe multiplexed over
37 time across multiple threads. </P> */
38
39 public class ThreadLocalAllocBuffer extends VMObject {
40 private static AddressField startField;
41 private static AddressField topField;
42 private static AddressField fastPathEndField;
43 private static CIntegerField desired_sizeField;
44
45 static {
46 VM.registerVMInitializedObserver(new Observer() {
47 public void update(Observable o, Object data) {
48 initialize(VM.getVM().getTypeDataBase());
49 }
50 });
51 }
52
53 private static synchronized void initialize(TypeDataBase db) {
54 Type type = db.lookupType("ThreadLocalAllocBuffer");
55
56 startField = type.getAddressField("_start");
57 topField = type.getAddressField("_top");
58 fastPathEndField = type.getAddressField("_fast_path_end");
59 desired_sizeField = type.getCIntegerField("_desired_size");
60 }
61
62 public ThreadLocalAllocBuffer(Address addr) {
63 super(addr);
64 }
65
66 public Address start() { return startField.getValue(addr); }
67 public Address fastPathEnd() { return fastPathEndField.getValue(addr); }
68 public Address top() { return topField.getValue(addr); }
69 public Address hardEnd() { return fastPathEnd().addOffsetTo(alignmentReserve()); }
70
71 private long alignmentReserve() {
72 return Oop.alignObjectSize(endReserve());
73 }
74
75 private long endReserve() {
76 long minFillerArraySize = Array.baseOffsetInBytes(BasicType.T_INT);
77 long reserveForAllocationPrefetch = VM.getVM().getReserveForAllocationPrefetch();
78 long heapWordSize = VM.getVM().getHeapWordSize();
79
80 return Math.max(minFillerArraySize, reserveForAllocationPrefetch * heapWordSize);
81 }
82
83 /** Support for iteration over heap -- not sure how this will
84 interact with GC in reflective system, but necessary for the
85 debugging mechanism */
86 public OopHandle startAsOopHandle() {
87 return startField.getOopHandle(addr);
88 }
89
92 debugging mechanism */
93 public OopHandle nextOopHandle(OopHandle handle, long size) {
94 return handle.addOffsetToAsOopHandle(size);
95 }
96
97 // public int size(); // FIXME: must adjust this to be in bytes
98 // public int availableSize(); // FIXME: must adjust this to be in bytes
99 public void print() {
100 printOn(System.out);
101 }
102
103 public boolean contains(Address p) {
104 if (top() == null) {
105 return false;
106 }
107 return (start().lessThanOrEqual(p) && top().greaterThan(p));
108 }
109
110 public void printOn(PrintStream tty) {
111 tty.println(" [" + start() + "," +
112 top() + "," + fastPathEnd() + ",{" + hardEnd() + "})");
113 }
114 }
|