35 public: |
35 public: |
36 enum AllocFailEnum { EXIT_OOM, RETURN_NULL }; |
36 enum AllocFailEnum { EXIT_OOM, RETURN_NULL }; |
37 }; |
37 }; |
38 typedef AllocFailStrategy::AllocFailEnum AllocFailType; |
38 typedef AllocFailStrategy::AllocFailEnum AllocFailType; |
39 |
39 |
40 // All classes in the virtual machine must be subclassed |
40 // The virtual machine must never call one of the implicitly declared |
41 // by one of the following allocation classes: |
41 // global allocation or deletion functions. (Such calls may result in |
|
42 // link-time or run-time errors.) For convenience and documentation of |
|
43 // intended use, classes in the virtual machine may be derived from one |
|
44 // of the following allocation classes, some of which define allocation |
|
45 // and deletion functions. |
|
46 // Note: std::malloc and std::free should never called directly. |
|
47 |
42 // |
48 // |
43 // For objects allocated in the resource area (see resourceArea.hpp). |
49 // For objects allocated in the resource area (see resourceArea.hpp). |
44 // - ResourceObj |
50 // - ResourceObj |
45 // |
51 // |
46 // For objects allocated in the C-heap (managed by: free & malloc). |
52 // For objects allocated in the C-heap (managed by: free & malloc and tracked with NMT) |
47 // - CHeapObj |
53 // - CHeapObj |
48 // |
54 // |
49 // For objects allocated on the stack. |
55 // For objects allocated on the stack. |
50 // - StackObj |
56 // - StackObj |
51 // |
|
52 // For embedded objects. |
|
53 // - ValueObj |
|
54 // |
57 // |
55 // For classes used as name spaces. |
58 // For classes used as name spaces. |
56 // - AllStatic |
59 // - AllStatic |
57 // |
60 // |
58 // For classes in Metaspace (class data) |
61 // For classes in Metaspace (class data) |
82 // FREE_C_HEAP_ARRAY(type, old) |
85 // FREE_C_HEAP_ARRAY(type, old) |
83 // FREE_C_HEAP_OBJ(objname, type, memflags) |
86 // FREE_C_HEAP_OBJ(objname, type, memflags) |
84 // char* AllocateHeap(size_t size, const char* name); |
87 // char* AllocateHeap(size_t size, const char* name); |
85 // void FreeHeap(void* p); |
88 // void FreeHeap(void* p); |
86 // |
89 // |
87 // C-heap allocation can be traced using +PrintHeapAllocation. |
|
88 // malloc and free should therefore never called directly. |
|
89 |
|
90 // Base class for objects allocated in the C-heap. |
|
91 |
90 |
92 // In non product mode we introduce a super class for all allocation classes |
91 // In non product mode we introduce a super class for all allocation classes |
93 // that supports printing. |
92 // that supports printing. |
94 // We avoid the superclass in product mode since some C++ compilers add |
93 // We avoid the superclass in product mode to save space. |
95 // a word overhead for empty super classes. |
|
96 |
94 |
97 #ifdef PRODUCT |
95 #ifdef PRODUCT |
98 #define ALLOCATION_SUPER_CLASS_SPEC |
96 #define ALLOCATION_SUPER_CLASS_SPEC |
99 #else |
97 #else |
100 #define ALLOCATION_SUPER_CLASS_SPEC : public AllocatedObj |
98 #define ALLOCATION_SUPER_CLASS_SPEC : public AllocatedObj |
186 #endif |
184 #endif |
187 void operator delete(void* p); |
185 void operator delete(void* p); |
188 void operator delete [](void* p); |
186 void operator delete [](void* p); |
189 }; |
187 }; |
190 |
188 |
191 // Base class for objects used as value objects. |
|
192 // Calling new or delete will result in fatal error. |
|
193 // |
|
194 // Portability note: Certain compilers (e.g. gcc) will |
|
195 // always make classes bigger if it has a superclass, even |
|
196 // if the superclass does not have any virtual methods or |
|
197 // instance fields. The HotSpot implementation relies on this |
|
198 // not to happen. So never make a ValueObj class a direct subclass |
|
199 // like this: |
|
200 // |
|
201 // class A { |
|
202 // ... |
|
203 // } |
|
204 // |
|
205 // be defined as a an empty string "". |
|
206 // |
|
207 class _ValueObj { |
|
208 private: |
|
209 void* operator new(size_t size) throw(); |
|
210 void operator delete(void* p); |
|
211 void* operator new [](size_t size) throw(); |
|
212 void operator delete [](void* p); |
|
213 }; |
|
214 |
|
215 |
|
216 // Base class for objects stored in Metaspace. |
189 // Base class for objects stored in Metaspace. |
217 // Calling delete will result in fatal error. |
190 // Calling delete will result in fatal error. |
218 // |
191 // |
219 // Do not inherit from something with a vptr because this class does |
192 // Do not inherit from something with a vptr because this class does |
220 // not introduce one. This class is used to allocate both shared read-only |
193 // not introduce one. This class is used to allocate both shared read-only |