bool BytecodePrinter::check_index(int i, int& cp_index, outputStream* st) { ConstantPool* constants = method()->constants(); int ilimit = constants->length(); Bytecodes::Code code = raw_code(); ConstantPoolCache* cache = NULL; if (Bytecodes::uses_cp_cache(code)) { bool okay = true; switch (code) { case Bytecodes::_fast_aldc: case Bytecodes::_fast_aldc_w: okay = check_obj_index(i, cp_index, st); break; case Bytecodes::_invokedynamic: okay = check_invokedynamic_index(i, cp_index, st); break; default: okay = check_cp_cache_index(i, cp_index, st); break; } if (!okay) return false; } // check cp index if (cp_index >= 0 && cp_index < ilimit) { if (WizardMode) st->print(" cp[%d]", cp_index); return true; } st->print_cr(" CP[%d] not in CP", cp_index); return false; }
bool BytecodePrinter::check_cp_cache_index(int i, int& cp_index, outputStream* st) { ConstantPool* constants = method()->constants(); int ilimit = constants->length(), climit = 0; Bytecodes::Code code = raw_code(); ConstantPoolCache* cache = constants->cache(); // If rewriter hasn't run, the index is the cp_index if (cache == NULL) { cp_index = i; return true; } //climit = cache->length(); // %%% private! size_t size = cache->size() * HeapWordSize; size -= sizeof(ConstantPoolCache); size /= sizeof(ConstantPoolCacheEntry); climit = (int) size; #ifdef ASSERT { const int CPCACHE_INDEX_TAG = ConstantPool::CPCACHE_INDEX_TAG; if (i >= CPCACHE_INDEX_TAG && i < climit + CPCACHE_INDEX_TAG) { i -= CPCACHE_INDEX_TAG; } else { st->print_cr(" CP[%d] missing bias?", i); return false; } } #endif //ASSERT if (i >= 0 && i < climit) { cp_index = cache->entry_at(i)->constant_pool_index(); } else { st->print_cr(" not in CP[*]?", i); return false; } return true; }