/vm/src/any/zone/zone.hh

http://github.com/ticking/self · C++ Header · 269 lines · 204 code · 55 blank · 10 comment · 13 complexity · 14b1454cb6646085ae8e3524ea5b2cc0 MD5 · raw file

  1. /* Sun-$Revision: 30.11 $ */
  2. /* Copyright 1992-2006 Sun Microsystems, Inc. and Stanford University.
  3. See the LICENSE file for license information. */
  4. # ifdef INTERFACE_PRAGMAS
  5. # pragma interface
  6. # endif
  7. oop PrintDebugSize_prim(oop rcvr);
  8. oop findNMethods_prim(oop rcvr, oop map, oop sel);
  9. oop printNMethodCode_prim(oop rcvr);
  10. # if defined(FAST_COMPILER) || defined(SIC_COMPILER)
  11. // The zone is the area of memory holding compiled methods (nmethods).
  12. class ScopeDesc;
  13. class PcDesc;
  14. class addrDesc;
  15. enum nm_compiler {nm_nic, nm_sic, nm_last};
  16. class zone: public CHeapObj {
  17. protected:
  18. int32* bottom;
  19. nmethod* LRUhand; // for LRU algorithm; sweeps through iZone
  20. bool needsICompaction;// need compaction of iZone
  21. bool needsSCompaction;// need compaction of dZone
  22. bool needsDCompaction;// need compaction of sZone
  23. bool _needsSweep; // need LRU sweep
  24. int32 compactDuration;// duration of last compaction
  25. timer zoneTimer; // timer for computation of above
  26. float minFreeFrac; // fraction of free space needed at compaction time
  27. IDManager* idManager;
  28. public: // for monitor
  29. Heap* iZone; // class nmethod + insts + locs
  30. Heap* dZone; // deps
  31. Heap* sZone; // scopes + pcs
  32. Stubs* stubs; // PICs
  33. Trapdoors* trapdoors; // long calls to far-away stubs
  34. public:
  35. codeTable* table; // hash table MethodLookupKey --> nmethod
  36. codeTable* debugTable;// same for nmethods with debugging code
  37. nmln rememberLink; // list of nmethods with pointers to newspace
  38. nmln replCandidates; // list of replacement candidates
  39. nmln zombies; // list of zombie methods
  40. static int32 frame_chain_nesting; // are nmethods on stacks chained? (>0 = yes)
  41. zone(int32& codeSize, int32& stubSize, int32& depSize, int32& debugSize);
  42. void* operator new(size_t size) {
  43. return AllocateHeap(size, "nmethod zone header"); }
  44. void clear();
  45. int32 capacity() {
  46. return iZone->capacity() + dZone->capacity()
  47. + sZone->capacity() + stubs->zone()->capacity(); }
  48. int32 used();
  49. int32 numberOfNMethods() { return idManager->usedIDs; }
  50. int used_per_compiler[nm_last];
  51. nmethod* alloc(int32 iLen, int32 sLen, int32 lLen, int32 dLen,
  52. char*& insts, nmethodScopes*& scopes,
  53. addrDesc*& locs, nmln*& deps);
  54. void free_nmethod(nmethod* m);
  55. void addToCodeTable(nmethod* nm, MethodLookupKey *k);
  56. nmethod* lookup(MethodLookupKey &k, bool needDebug = false);
  57. void compact(bool forced = false);
  58. void compactAll() {
  59. needsICompaction = needsSCompaction = needsDCompaction = true;
  60. compact(true); }
  61. bool needsCompaction() {
  62. return needsICompaction || needsSCompaction || needsDCompaction; }
  63. bool needsWork() { return needsCompaction() || _needsSweep; }
  64. bool needsSweep() { return _needsSweep; }
  65. void doWork();
  66. void doSweep();
  67. void flush();
  68. void flushZombies();
  69. void markAllUnused();
  70. void flushUnused();
  71. void flush_inline_cache();
  72. int32 findReplCandidates(int32 needed);
  73. void nonCombiningMode() {
  74. iZone->combineMode = dZone->combineMode = sZone->combineMode = false;
  75. }
  76. // frame chaining: see FrameChainer below
  77. void chainFrames() {
  78. assert(frame_chain_nesting >= 0, "frame_chain_nesting should be nonnegative");
  79. if (frame_chain_nesting++ == 0) doChainFrames();
  80. }
  81. void unchainFrames() {
  82. assert(frame_chain_nesting > 0, "frame_chain_nesting should be positive");
  83. if (--frame_chain_nesting == 0) doUnchainFrames();
  84. }
  85. // zone creation (for PPC) must put stubs right after iZone
  86. pc_t code_start() { return Memory->code-> iZone->startAddr(); }
  87. pc_t code_end() { return Memory->code->stubs->zone()->endAddr(); }
  88. bool isSelfPC(void* p) { return code_start() <= p && p < code_end(); }
  89. bool contains(void *p) {
  90. return iZone->contains(p) || dZone->contains(p) || sZone->contains(p); }
  91. nmethod* findNMethod(void* start);
  92. nmethod* findNMethod_maybe(void* start); // slow!
  93. void findNMethodOrMap(nmln *n, nmethod* &nm, slotsMapDeps* &s);
  94. void nmethods_do(nmethodDoFn f);
  95. void oops_do(oopsDoFn f);
  96. void scavenge_contents();
  97. void gc_mark_contents();
  98. void gc_unmark_contents();
  99. void switch_pointers(oop from, oop to);
  100. bool verify();
  101. void read_snapshot(FILE* f);
  102. void write_snapshot(FILE* f);
  103. #ifdef UNUSED
  104. void relocate();
  105. #endif
  106. void relocate_nmln(nmln*);
  107. void fixup();
  108. void print();
  109. void print_stats();
  110. void print_nmethod_histogram(fint size);
  111. nmethod* first_nm() { return (nmethod*)(iZone->firstUsed()); }
  112. nmethod* next_nm(nmethod* p) { return (nmethod*)(iZone->nextUsed(p)); }
  113. char* instsStart();
  114. int32 instsSize();
  115. int32 LRU_time();
  116. int32 sweeper(int32 maxVisit, int32 maxReclaim,
  117. int32* nvisited = NULL, int32* nbytesReclaimed = NULL);
  118. int32 nextNMethodID();
  119. char *allocateDeps(fint nbytes);
  120. void deallocateDeps(char *d, fint nbytes) { dZone->deallocate(d, nbytes); }
  121. void setDepsMap(nmln *deps, slotsMapDeps *m);
  122. protected:
  123. void print_helper(bool stats);
  124. void adjustPolicy();
  125. int32 flushNextMethod(int32 needed);
  126. inline nmethod* next_circular_nm(nmethod* nm);
  127. void doChainFrames();
  128. void doUnchainFrames();
  129. friend void moveInsts(char* from, char* to, int32 size);
  130. friend void printAllNMethods();
  131. friend void sweepTrigger();
  132. // constructor helpers:
  133. private:
  134. void round_sizes(int32& codeSize, int32& stubSize, int32& depSize, int32& debugSize);
  135. void set_sizes_for_statically_allocated_code_and_stub_area(
  136. int32& codeSize, int32& stubSize, int32& depSize, int32& debugSize,
  137. char*& stb);
  138. void set_sizes_and_allocate_code_and_stub_area(
  139. int32& codeSize, int32& stubSize, int32& depSize, int32& debugSize,
  140. char*& stb);
  141. void allocate_pieces(int32& codeSize, int32& stubSize, int32& depSize, int32& debugSize, char* stb);
  142. void check_allocations();
  143. void allocate_trapdoors_at_zone_base_stealing_from_code_space(int32& codeSize);
  144. void allocate_idManager(fint maxNMs);
  145. void setup_LRU();
  146. void allocate_useCount(fint maxNMs);
  147. };
  148. // use this to make sure frames are unchained when returning from function
  149. class FrameChainer {
  150. zone* z;
  151. public:
  152. FrameChainer(zone* zz) { z = zz; zz->chainFrames(); }
  153. ~FrameChainer() { z->unchainFrames(); }
  154. };
  155. // holds usage information for nmethods (or index of next free nmethod ID
  156. // if not assigned to any nmethod)
  157. class LRUcount {
  158. public:
  159. uint16 unused; // nmethod prologue clears BOTH fields to 0
  160. uint16 lastUsed; // time of last use
  161. LRUcount() { ShouldNotCallThis(); } // shouldn't create
  162. LRUcount(LRUcount &/*l*/) { ShouldNotCallThis(); } // shouldn't create
  163. #ifdef UNUSED
  164. int32 asInt() { return *(int32*)this; }
  165. #endif
  166. void set(int32 i) { *(int32*)this = i; }
  167. };
  168. extern LRUcount* LRUtable; // for optimized methods
  169. extern int32* LRUflag; // == LRUtable, just different type for convenience
  170. extern int32* useCount; // table with counts for unoptimized methods
  171. #define APPLY_TO_ZONES(template) \
  172. template(Memory->code->iZone); \
  173. template(Memory->code->dZone); \
  174. template(Memory->code->sZone); \
  175. template(Memory->code->stubs->zone()); \
  176. # else // make a dummy zone
  177. class zone: public CHeapObj {
  178. public:
  179. bool contains(void *p) { Unused(p); return false;}
  180. int32 capacity() { return 0; }
  181. void compactAll() {}
  182. void flush() {}
  183. void flushUnused() {}
  184. void flushZombies() {}
  185. void flush_inline_cache() {}
  186. void markAllUnused() {}
  187. void flushInlineCache() {}
  188. void print_nmethod_histogram(fint size) { Unused(size); }
  189. void print_stats() {}
  190. zone(int32& iSize, int32& dSize, int32& sSize, int32& stSize) {
  191. iSize = dSize = sSize = stSize = 0; }
  192. void switch_pointers(oop from, oop to) { Unused(from); Unused(to); }
  193. void read_snapshot( FILE* f);
  194. void write_snapshot( FILE* f);
  195. void fixup() {}
  196. void verify() {}
  197. void clear() {}
  198. void print() {}
  199. void scavenge_contents() {}
  200. void gc_mark_contents() {}
  201. void gc_unmark_contents() {}
  202. void nonCombiningMode() {}
  203. char *allocateDeps(fint nbytes) { // no zone; no deps
  204. Unused(nbytes); ShouldNotCallThis(); return NULL; }
  205. void deallocateDeps(char *d, fint nbytes) {
  206. Unused(d); Unused(nbytes); ShouldNotCallThis(); }
  207. void setDepsMap(nmln *deps, slotsMapDeps *m) {
  208. Unused(deps); Unused(m); ShouldNotCallThis(); }
  209. void chainFrames() {}
  210. void unchainFrames() {}
  211. void findNMethodOrMap(nmln *n, nmethod* &nm, slotsMapDeps* &s);
  212. };
  213. #define APPLY_TO_ZONES(template)
  214. # endif // defined(FAST_COMPILER) || defined(SIC_COMPILER)