Mercurial > hg > truffle
comparison src/share/vm/runtime/sharedRuntime.cpp @ 6197:d2a62e0f25eb
6995781: Native Memory Tracking (Phase 1)
7151532: DCmd for hotspot native memory tracking
Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd
Reviewed-by: acorn, coleenp, fparain
author | zgu |
---|---|
date | Thu, 28 Jun 2012 17:03:16 -0400 |
parents | 09d00c18e323 |
children | 1d7922586cf6 |
comparison
equal
deleted
inserted
replaced
6174:74533f63b116 | 6197:d2a62e0f25eb |
---|---|
2115 #endif | 2115 #endif |
2116 | 2116 |
2117 | 2117 |
2118 // A simple wrapper class around the calling convention information | 2118 // A simple wrapper class around the calling convention information |
2119 // that allows sharing of adapters for the same calling convention. | 2119 // that allows sharing of adapters for the same calling convention. |
2120 class AdapterFingerPrint : public CHeapObj { | 2120 class AdapterFingerPrint : public CHeapObj<mtCode> { |
2121 private: | 2121 private: |
2122 union { | 2122 union { |
2123 int _compact[3]; | 2123 int _compact[3]; |
2124 int* _fingerprint; | 2124 int* _fingerprint; |
2125 } _value; | 2125 } _value; |
2172 // of the time. | 2172 // of the time. |
2173 _length = -len; | 2173 _length = -len; |
2174 ptr = _value._compact; | 2174 ptr = _value._compact; |
2175 } else { | 2175 } else { |
2176 _length = len; | 2176 _length = len; |
2177 _value._fingerprint = NEW_C_HEAP_ARRAY(int, _length); | 2177 _value._fingerprint = NEW_C_HEAP_ARRAY(int, _length, mtCode); |
2178 ptr = _value._fingerprint; | 2178 ptr = _value._fingerprint; |
2179 } | 2179 } |
2180 | 2180 |
2181 // Now pack the BasicTypes with 8 per int | 2181 // Now pack the BasicTypes with 8 per int |
2182 int sig_index = 0; | 2182 int sig_index = 0; |
2191 } | 2191 } |
2192 } | 2192 } |
2193 | 2193 |
2194 ~AdapterFingerPrint() { | 2194 ~AdapterFingerPrint() { |
2195 if (_length > 0) { | 2195 if (_length > 0) { |
2196 FREE_C_HEAP_ARRAY(int, _value._fingerprint); | 2196 FREE_C_HEAP_ARRAY(int, _value._fingerprint, mtCode); |
2197 } | 2197 } |
2198 } | 2198 } |
2199 | 2199 |
2200 int value(int index) { | 2200 int value(int index) { |
2201 if (_length < 0) { | 2201 if (_length < 0) { |
2249 } | 2249 } |
2250 }; | 2250 }; |
2251 | 2251 |
2252 | 2252 |
2253 // A hashtable mapping from AdapterFingerPrints to AdapterHandlerEntries | 2253 // A hashtable mapping from AdapterFingerPrints to AdapterHandlerEntries |
2254 class AdapterHandlerTable : public BasicHashtable { | 2254 class AdapterHandlerTable : public BasicHashtable<mtCode> { |
2255 friend class AdapterHandlerTableIterator; | 2255 friend class AdapterHandlerTableIterator; |
2256 | 2256 |
2257 private: | 2257 private: |
2258 | 2258 |
2259 #ifndef PRODUCT | 2259 #ifndef PRODUCT |
2263 static int _hits; // number of successful lookups | 2263 static int _hits; // number of successful lookups |
2264 static int _compact; // number of equals calls with compact signature | 2264 static int _compact; // number of equals calls with compact signature |
2265 #endif | 2265 #endif |
2266 | 2266 |
2267 AdapterHandlerEntry* bucket(int i) { | 2267 AdapterHandlerEntry* bucket(int i) { |
2268 return (AdapterHandlerEntry*)BasicHashtable::bucket(i); | 2268 return (AdapterHandlerEntry*)BasicHashtable<mtCode>::bucket(i); |
2269 } | 2269 } |
2270 | 2270 |
2271 public: | 2271 public: |
2272 AdapterHandlerTable() | 2272 AdapterHandlerTable() |
2273 : BasicHashtable(293, sizeof(AdapterHandlerEntry)) { } | 2273 : BasicHashtable<mtCode>(293, sizeof(AdapterHandlerEntry)) { } |
2274 | 2274 |
2275 // Create a new entry suitable for insertion in the table | 2275 // Create a new entry suitable for insertion in the table |
2276 AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry) { | 2276 AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry) { |
2277 AdapterHandlerEntry* entry = (AdapterHandlerEntry*)BasicHashtable::new_entry(fingerprint->compute_hash()); | 2277 AdapterHandlerEntry* entry = (AdapterHandlerEntry*)BasicHashtable<mtCode>::new_entry(fingerprint->compute_hash()); |
2278 entry->init(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry); | 2278 entry->init(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry); |
2279 return entry; | 2279 return entry; |
2280 } | 2280 } |
2281 | 2281 |
2282 // Insert an entry into the table | 2282 // Insert an entry into the table |
2285 add_entry(index, entry); | 2285 add_entry(index, entry); |
2286 } | 2286 } |
2287 | 2287 |
2288 void free_entry(AdapterHandlerEntry* entry) { | 2288 void free_entry(AdapterHandlerEntry* entry) { |
2289 entry->deallocate(); | 2289 entry->deallocate(); |
2290 BasicHashtable::free_entry(entry); | 2290 BasicHashtable<mtCode>::free_entry(entry); |
2291 } | 2291 } |
2292 | 2292 |
2293 // Find a entry with the same fingerprint if it exists | 2293 // Find a entry with the same fingerprint if it exists |
2294 AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt) { | 2294 AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt) { |
2295 NOT_PRODUCT(_lookups++); | 2295 NOT_PRODUCT(_lookups++); |
2570 | 2570 |
2571 | 2571 |
2572 void AdapterHandlerEntry::deallocate() { | 2572 void AdapterHandlerEntry::deallocate() { |
2573 delete _fingerprint; | 2573 delete _fingerprint; |
2574 #ifdef ASSERT | 2574 #ifdef ASSERT |
2575 if (_saved_code) FREE_C_HEAP_ARRAY(unsigned char, _saved_code); | 2575 if (_saved_code) FREE_C_HEAP_ARRAY(unsigned char, _saved_code, mtCode); |
2576 if (_saved_sig) FREE_C_HEAP_ARRAY(Basictype, _saved_sig); | 2576 if (_saved_sig) FREE_C_HEAP_ARRAY(Basictype, _saved_sig, mtCode); |
2577 #endif | 2577 #endif |
2578 } | 2578 } |
2579 | 2579 |
2580 | 2580 |
2581 #ifdef ASSERT | 2581 #ifdef ASSERT |
2582 // Capture the code before relocation so that it can be compared | 2582 // Capture the code before relocation so that it can be compared |
2583 // against other versions. If the code is captured after relocation | 2583 // against other versions. If the code is captured after relocation |
2584 // then relative instructions won't be equivalent. | 2584 // then relative instructions won't be equivalent. |
2585 void AdapterHandlerEntry::save_code(unsigned char* buffer, int length, int total_args_passed, BasicType* sig_bt) { | 2585 void AdapterHandlerEntry::save_code(unsigned char* buffer, int length, int total_args_passed, BasicType* sig_bt) { |
2586 _saved_code = NEW_C_HEAP_ARRAY(unsigned char, length); | 2586 _saved_code = NEW_C_HEAP_ARRAY(unsigned char, length, mtCode); |
2587 _code_length = length; | 2587 _code_length = length; |
2588 memcpy(_saved_code, buffer, length); | 2588 memcpy(_saved_code, buffer, length); |
2589 _total_args_passed = total_args_passed; | 2589 _total_args_passed = total_args_passed; |
2590 _saved_sig = NEW_C_HEAP_ARRAY(BasicType, _total_args_passed); | 2590 _saved_sig = NEW_C_HEAP_ARRAY(BasicType, _total_args_passed, mtCode); |
2591 memcpy(_saved_sig, sig_bt, _total_args_passed * sizeof(BasicType)); | 2591 memcpy(_saved_sig, sig_bt, _total_args_passed * sizeof(BasicType)); |
2592 } | 2592 } |
2593 | 2593 |
2594 | 2594 |
2595 bool AdapterHandlerEntry::compare_code(unsigned char* buffer, int length, int total_args_passed, BasicType* sig_bt) { | 2595 bool AdapterHandlerEntry::compare_code(unsigned char* buffer, int length, int total_args_passed, BasicType* sig_bt) { |
2891 | 2891 |
2892 methodOop moop = fr.interpreter_frame_method(); | 2892 methodOop moop = fr.interpreter_frame_method(); |
2893 int max_locals = moop->max_locals(); | 2893 int max_locals = moop->max_locals(); |
2894 // Allocate temp buffer, 1 word per local & 2 per active monitor | 2894 // Allocate temp buffer, 1 word per local & 2 per active monitor |
2895 int buf_size_words = max_locals + active_monitor_count*2; | 2895 int buf_size_words = max_locals + active_monitor_count*2; |
2896 intptr_t *buf = NEW_C_HEAP_ARRAY(intptr_t,buf_size_words); | 2896 intptr_t *buf = NEW_C_HEAP_ARRAY(intptr_t,buf_size_words, mtCode); |
2897 | 2897 |
2898 // Copy the locals. Order is preserved so that loading of longs works. | 2898 // Copy the locals. Order is preserved so that loading of longs works. |
2899 // Since there's no GC I can copy the oops blindly. | 2899 // Since there's no GC I can copy the oops blindly. |
2900 assert( sizeof(HeapWord)==sizeof(intptr_t), "fix this code"); | 2900 assert( sizeof(HeapWord)==sizeof(intptr_t), "fix this code"); |
2901 Copy::disjoint_words((HeapWord*)fr.interpreter_frame_local_at(max_locals-1), | 2901 Copy::disjoint_words((HeapWord*)fr.interpreter_frame_local_at(max_locals-1), |
2921 | 2921 |
2922 return buf; | 2922 return buf; |
2923 JRT_END | 2923 JRT_END |
2924 | 2924 |
2925 JRT_LEAF(void, SharedRuntime::OSR_migration_end( intptr_t* buf) ) | 2925 JRT_LEAF(void, SharedRuntime::OSR_migration_end( intptr_t* buf) ) |
2926 FREE_C_HEAP_ARRAY(intptr_t,buf); | 2926 FREE_C_HEAP_ARRAY(intptr_t,buf, mtCode); |
2927 JRT_END | 2927 JRT_END |
2928 | 2928 |
2929 bool AdapterHandlerLibrary::contains(CodeBlob* b) { | 2929 bool AdapterHandlerLibrary::contains(CodeBlob* b) { |
2930 AdapterHandlerTableIterator iter(_adapters); | 2930 AdapterHandlerTableIterator iter(_adapters); |
2931 while (iter.has_next()) { | 2931 while (iter.has_next()) { |