< prev index next >

src/hotspot/share/code/stubs.cpp


99 Stub* StubQueue::stub_containing(address pc) const {                                                                                 
100   if (contains(pc)) {                                                                                                                
101     for (Stub* s = first(); s != NULL; s = next(s)) {                                                                                
102       if (stub_contains(s, pc)) return s;                                                                                            
103     }                                                                                                                                
104   }                                                                                                                                  
105   return NULL;                                                                                                                       
106 }                                                                                                                                    
107 
108 
109 Stub* StubQueue::request_committed(int code_size) {                                                                                  
110   Stub* s = request(code_size);                                                                                                      
111   CodeStrings strings;                                                                                                               
112   if (s != NULL) commit(code_size, strings);                                                                                         
113   return s;                                                                                                                          
114 }                                                                                                                                    
115 
116 
117 Stub* StubQueue::request(int requested_code_size) {                                                                                  
118   assert(requested_code_size > 0, "requested_code_size must be > 0");                                                                
119   if (_mutex != NULL) _mutex->lock();                                                                                                
120   Stub* s = current_stub();                                                                                                          
121   int requested_size = align_up(stub_code_size_to_size(requested_code_size), CodeEntryAlignment);                                    
122   if (requested_size <= available_space()) {                                                                                         
123     if (is_contiguous()) {                                                                                                           
124       // Queue: |...|XXXXXXX|.............|                                                                                          
125       //        ^0  ^begin  ^end          ^size = limit                                                                              
126       assert(_buffer_limit == _buffer_size, "buffer must be fully usable");                                                          
127       if (_queue_end + requested_size <= _buffer_size) {                                                                             
128         // code fits in at the end => nothing to do                                                                                  
129         CodeStrings strings;                                                                                                         
130         stub_initialize(s, requested_size, strings);                                                                                 
131         return s;                                                                                                                    
132       } else {                                                                                                                       
133         // stub doesn't fit in at the queue end                                                                                      
134         // => reduce buffer limit & wrap around                                                                                      
135         assert(!is_empty(), "just checkin'");                                                                                        
136         _buffer_limit = _queue_end;                                                                                                  
137         _queue_end = 0;                                                                                                              
138       }                                                                                                                              

99 Stub* StubQueue::stub_containing(address pc) const {
100   if (contains(pc)) {
101     for (Stub* s = first(); s != NULL; s = next(s)) {
102       if (stub_contains(s, pc)) return s;
103     }
104   }
105   return NULL;
106 }
107 
108 
109 Stub* StubQueue::request_committed(int code_size) {
110   Stub* s = request(code_size);
111   CodeStrings strings;
112   if (s != NULL) commit(code_size, strings);
113   return s;
114 }
115 
116 
117 Stub* StubQueue::request(int requested_code_size) {
118   assert(requested_code_size > 0, "requested_code_size must be > 0");
119   if (_mutex != NULL) _mutex->lock_without_safepoint_check();
120   Stub* s = current_stub();
121   int requested_size = align_up(stub_code_size_to_size(requested_code_size), CodeEntryAlignment);
122   if (requested_size <= available_space()) {
123     if (is_contiguous()) {
124       // Queue: |...|XXXXXXX|.............|
125       //        ^0  ^begin  ^end          ^size = limit
126       assert(_buffer_limit == _buffer_size, "buffer must be fully usable");
127       if (_queue_end + requested_size <= _buffer_size) {
128         // code fits in at the end => nothing to do
129         CodeStrings strings;
130         stub_initialize(s, requested_size, strings);
131         return s;
132       } else {
133         // stub doesn't fit in at the queue end
134         // => reduce buffer limit & wrap around
135         assert(!is_empty(), "just checkin'");
136         _buffer_limit = _queue_end;
137         _queue_end = 0;
138       }

189   _number_of_stubs--;                                                                                                                
190 }                                                                                                                                    
191 
192 
193 void StubQueue::remove_first(int n) {                                                                                                
194   int i = MIN2(n, number_of_stubs());                                                                                                
195   while (i-- > 0) remove_first();                                                                                                    
196 }                                                                                                                                    
197 
198 
199 void StubQueue::remove_all(){                                                                                                        
200   debug_only(verify();)                                                                                                              
201   remove_first(number_of_stubs());                                                                                                   
202   assert(number_of_stubs() == 0, "sanity check");                                                                                    
203 }                                                                                                                                    
204 
205 
206 void StubQueue::verify() {                                                                                                           
207   // verify only if initialized                                                                                                      
208   if (_stub_buffer == NULL) return;                                                                                                  
209   MutexLockerEx lock(_mutex);                                                                                                        
210   // verify index boundaries                                                                                                         
211   guarantee(0 <= _buffer_size, "buffer size must be positive");                                                                      
212   guarantee(0 <= _buffer_limit && _buffer_limit <= _buffer_size , "_buffer_limit out of bounds");                                    
213   guarantee(0 <= _queue_begin  && _queue_begin  <  _buffer_limit, "_queue_begin out of bounds");                                     
214   guarantee(0 <= _queue_end    && _queue_end    <= _buffer_limit, "_queue_end   out of bounds");                                     
215   // verify alignment                                                                                                                
216   guarantee(_buffer_size  % CodeEntryAlignment == 0, "_buffer_size  not aligned");                                                   
217   guarantee(_buffer_limit % CodeEntryAlignment == 0, "_buffer_limit not aligned");                                                   
218   guarantee(_queue_begin  % CodeEntryAlignment == 0, "_queue_begin  not aligned");                                                   
219   guarantee(_queue_end    % CodeEntryAlignment == 0, "_queue_end    not aligned");                                                   
220   // verify buffer limit/size relationship                                                                                           
221   if (is_contiguous()) {                                                                                                             
222     guarantee(_buffer_limit == _buffer_size, "_buffer_limit must equal _buffer_size");                                               
223   }                                                                                                                                  
224   // verify contents                                                                                                                 
225   int n = 0;                                                                                                                         
226   for (Stub* s = first(); s != NULL; s = next(s)) {                                                                                  
227     stub_verify(s);                                                                                                                  
228     n++;                                                                                                                             
229   }                                                                                                                                  
230   guarantee(n == number_of_stubs(), "number of stubs inconsistent");                                                                 
231   guarantee(_queue_begin != _queue_end || n == 0, "buffer indices must be the same");                                                
232 }                                                                                                                                    
233 
234 
235 void StubQueue::print() {                                                                                                            
236   MutexLockerEx lock(_mutex);                                                                                                        
237   for (Stub* s = first(); s != NULL; s = next(s)) {                                                                                  
238     stub_print(s);                                                                                                                   
239   }                                                                                                                                  
240 }                                                                                                                                    
241                                                                                                                                      

189   _number_of_stubs--;
190 }
191 
192 
193 void StubQueue::remove_first(int n) {
194   int i = MIN2(n, number_of_stubs());
195   while (i-- > 0) remove_first();
196 }
197 
198 
199 void StubQueue::remove_all(){
200   debug_only(verify();)
201   remove_first(number_of_stubs());
202   assert(number_of_stubs() == 0, "sanity check");
203 }
204 
205 
206 void StubQueue::verify() {
207   // verify only if initialized
208   if (_stub_buffer == NULL) return;
209   MutexLockerEx lock(_mutex, Mutex::_no_safepoint_check_flag);
210   // verify index boundaries
211   guarantee(0 <= _buffer_size, "buffer size must be positive");
212   guarantee(0 <= _buffer_limit && _buffer_limit <= _buffer_size , "_buffer_limit out of bounds");
213   guarantee(0 <= _queue_begin  && _queue_begin  <  _buffer_limit, "_queue_begin out of bounds");
214   guarantee(0 <= _queue_end    && _queue_end    <= _buffer_limit, "_queue_end   out of bounds");
215   // verify alignment
216   guarantee(_buffer_size  % CodeEntryAlignment == 0, "_buffer_size  not aligned");
217   guarantee(_buffer_limit % CodeEntryAlignment == 0, "_buffer_limit not aligned");
218   guarantee(_queue_begin  % CodeEntryAlignment == 0, "_queue_begin  not aligned");
219   guarantee(_queue_end    % CodeEntryAlignment == 0, "_queue_end    not aligned");
220   // verify buffer limit/size relationship
221   if (is_contiguous()) {
222     guarantee(_buffer_limit == _buffer_size, "_buffer_limit must equal _buffer_size");
223   }
224   // verify contents
225   int n = 0;
226   for (Stub* s = first(); s != NULL; s = next(s)) {
227     stub_verify(s);
228     n++;
229   }
230   guarantee(n == number_of_stubs(), "number of stubs inconsistent");
231   guarantee(_queue_begin != _queue_end || n == 0, "buffer indices must be the same");
232 }
233 
234 
235 void StubQueue::print() {
236   MutexLockerEx lock(_mutex, Mutex::_no_safepoint_check_flag);
237   for (Stub* s = first(); s != NULL; s = next(s)) {
238     stub_print(s);
239   }
240 }

< prev index next >