238 return; |
238 return; |
239 } |
239 } |
240 |
240 |
241 |
241 |
242 int Method::bci_from(address bcp) const { |
242 int Method::bci_from(address bcp) const { |
|
243 if (is_native() && bcp == 0) { |
|
244 return 0; |
|
245 } |
243 #ifdef ASSERT |
246 #ifdef ASSERT |
244 { ResourceMark rm; |
247 { ResourceMark rm; |
245 assert(is_native() && bcp == code_base() || contains(bcp) || is_error_reported(), |
248 assert(is_native() && bcp == code_base() || contains(bcp) || is_error_reported(), |
246 err_msg("bcp doesn't belong to this method: bcp: " INTPTR_FORMAT ", method: %s", bcp, name_and_sig_as_C_string())); |
249 err_msg("bcp doesn't belong to this method: bcp: " INTPTR_FORMAT ", method: %s", bcp, name_and_sig_as_C_string())); |
247 } |
250 } |
248 #endif |
251 #endif |
249 return bcp - code_base(); |
252 return bcp - code_base(); |
250 } |
253 } |
251 |
254 |
252 |
255 |
253 // Return (int)bcx if it appears to be a valid BCI. |
256 int Method::validate_bci(int bci) const { |
254 // Return bci_from((address)bcx) if it appears to be a valid BCP. |
257 return (bci == 0 || bci < code_size()) ? bci : -1; |
|
258 } |
|
259 |
|
260 // Return bci if it appears to be a valid bcp |
255 // Return -1 otherwise. |
261 // Return -1 otherwise. |
256 // Used by profiling code, when invalid data is a possibility. |
262 // Used by profiling code, when invalid data is a possibility. |
257 // The caller is responsible for validating the Method* itself. |
263 // The caller is responsible for validating the Method* itself. |
258 int Method::validate_bci_from_bcx(intptr_t bcx) const { |
264 int Method::validate_bci_from_bcp(address bcp) const { |
259 // keep bci as -1 if not a valid bci |
265 // keep bci as -1 if not a valid bci |
260 int bci = -1; |
266 int bci = -1; |
261 if (bcx == 0 || (address)bcx == code_base()) { |
267 if (bcp == 0 || bcp == code_base()) { |
262 // code_size() may return 0 and we allow 0 here |
268 // code_size() may return 0 and we allow 0 here |
263 // the method may be native |
269 // the method may be native |
264 bci = 0; |
270 bci = 0; |
265 } else if (frame::is_bci(bcx)) { |
271 } else if (contains(bcp)) { |
266 if (bcx < code_size()) { |
272 bci = bcp - code_base(); |
267 bci = (int)bcx; |
|
268 } |
|
269 } else if (contains((address)bcx)) { |
|
270 bci = (address)bcx - code_base(); |
|
271 } |
273 } |
272 // Assert that if we have dodged any asserts, bci is negative. |
274 // Assert that if we have dodged any asserts, bci is negative. |
273 assert(bci == -1 || bci == bci_from(bcp_from(bci)), "sane bci if >=0"); |
275 assert(bci == -1 || bci == bci_from(bcp_from(bci)), "sane bci if >=0"); |
274 return bci; |
276 return bci; |
275 } |
277 } |