// ------------------------------------------------------------------ // ciMethod::load_code // // Load the bytecodes and exception handler table for this method. void ciMethod::load_code() { VM_ENTRY_MARK; assert(is_loaded(), "only loaded methods have code"); methodOop me = get_methodOop(); Arena* arena = CURRENT_THREAD_ENV->arena(); // Load the bytecodes. _code = (address)arena->Amalloc(code_size()); memcpy(_code, me->code_base(), code_size()); // Revert any breakpoint bytecodes in ci's copy if (me->number_of_breakpoints() > 0) { BreakpointInfo* bp = instanceKlass::cast(me->method_holder())->breakpoints(); for (; bp != NULL; bp = bp->next()) { if (bp->match(me)) { code_at_put(bp->bci(), bp->orig_bytecode()); } } } // And load the exception table. typeArrayOop exc_table = me->exception_table(); // Allocate one extra spot in our list of exceptions. This // last entry will be used to represent the possibility that // an exception escapes the method. See ciExceptionHandlerStream // for details. _exception_handlers = (ciExceptionHandler**)arena->Amalloc(sizeof(ciExceptionHandler*) * (_handler_count + 1)); if (_handler_count > 0) { for (int i=0; i<_handler_count; i++) { int base = i*4; _exception_handlers[i] = new (arena) ciExceptionHandler( holder(), /* start */ exc_table->int_at(base), /* limit */ exc_table->int_at(base+1), /* goto pc */ exc_table->int_at(base+2), /* cp index */ exc_table->int_at(base+3)); } } // Put an entry at the end of our list to represent the possibility // of exceptional exit. _exception_handlers[_handler_count] = new (arena) ciExceptionHandler(holder(), 0, code_size(), -1, 0); if (CIPrintMethodCodes) { print_codes(); } }
// Size Statistics void ConstMethod::collect_statistics(KlassSizeStats *sz) const { int n1, n2, n3; sz->_const_method_bytes += (n1 = sz->count(this)); sz->_bytecode_bytes += (n2 = code_size()); sz->_stackmap_bytes += (n3 = sz->count_array(stackmap_data())); // Count method annotations int a1 = 0, a2 = 0, a3 = 0, a4 = 0; if (has_method_annotations()) { sz->_methods_annotations_bytes += (a1 = sz->count_array(method_annotations())); } if (has_parameter_annotations()) { sz->_methods_parameter_annotations_bytes += (a2 = sz->count_array(parameter_annotations())); } if (has_type_annotations()) { sz->_methods_type_annotations_bytes += (a3 = sz->count_array(type_annotations())); } if (has_default_annotations()) { sz->_methods_default_annotations_bytes += (a4 = sz->count_array(default_annotations())); } int size_annotations = a1 + a2 + a3 + a4; sz->_method_all_bytes += n1 + n3 + size_annotations; // note: n2 is part of n3 sz->_ro_bytes += n1 + n3 + size_annotations; }
void ConstMethod::verify_on(outputStream* st) { guarantee(is_constMethod(), "object must be constMethod"); // Verification can occur during oop construction before the method or // other fields have been initialized. guarantee(method()->is_method(), "should be method"); address m_end = (address)((intptr_t) this + size()); address compressed_table_start = code_end(); guarantee(compressed_table_start <= m_end, "invalid method layout"); address compressed_table_end = compressed_table_start; // Verify line number table if (has_linenumber_table()) { CompressedLineNumberReadStream stream(compressed_linenumber_table()); while (stream.read_pair()) { guarantee(stream.bci() >= 0 && stream.bci() <= code_size(), "invalid bci in line number table"); } compressed_table_end += stream.position(); } guarantee(compressed_table_end <= m_end, "invalid method layout"); // Verify checked exceptions, exception table and local variable tables if (has_method_parameters()) { u2* addr = method_parameters_length_addr(); guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout"); } if (has_checked_exceptions()) { u2* addr = checked_exceptions_length_addr(); guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout"); } if (has_exception_handler()) { u2* addr = exception_table_length_addr(); guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout"); } if (has_localvariable_table()) { u2* addr = localvariable_table_length_addr(); guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout"); } // Check compressed_table_end relative to uncompressed_table_start u2* uncompressed_table_start; if (has_localvariable_table()) { uncompressed_table_start = (u2*) localvariable_table_start(); } else if (has_exception_handler()) { uncompressed_table_start = (u2*) exception_table_start(); } else if (has_checked_exceptions()) { uncompressed_table_start = (u2*) checked_exceptions_start(); } else if (has_method_parameters()) { uncompressed_table_start = (u2*) method_parameters_start(); } else { uncompressed_table_start = (u2*) m_end; } int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end; int max_gap = align_metadata_size(1)*BytesPerWord; guarantee(gap >= 0 && gap < max_gap, "invalid method layout"); }
void InterpreterCodelet::print_on(outputStream* st) const { if (PrintInterpreter) { st->cr(); st->print_cr("----------------------------------------------------------------------"); } if (description() != NULL) st->print("%s ", description()); if (bytecode() >= 0 ) st->print("%d %s ", bytecode(), Bytecodes::name(bytecode())); st->print_cr("[" INTPTR_FORMAT ", " INTPTR_FORMAT "] %d bytes", code_begin(), code_end(), code_size()); if (PrintInterpreter) { st->cr(); Disassembler::decode(code_begin(), code_end(), st); } }
void InterpreterCodelet::print_on(outputStream* st) const { ttyLocker ttyl; if (PrintInterpreter) { st->cr(); st->print_cr("----------------------------------------------------------------------"); } if (description() != NULL) st->print("%s ", description()); if (bytecode() >= 0 ) st->print("%d %s ", bytecode(), Bytecodes::name(bytecode())); st->print_cr("[" INTPTR_FORMAT ", " INTPTR_FORMAT "] %d bytes", p2i(code_begin()), p2i(code_end()), code_size()); if (PrintInterpreter) { st->cr(); Disassembler::decode(code_begin(), code_end(), st, DEBUG_ONLY(_strings) NOT_DEBUG(CodeStrings())); } }
void testeventmsg::msgCode() { char buf[51],bufI[51],bufE[51],bufD[51]; const int sz = sizeof(buf); MsgCode code_size(buf,sz); MsgCode code_nosize(buf); MsgCode code_with_init(bufI,MsgCode::INIT); MsgCode code_with_event(bufE,MsgCode::EVENT); MsgCode code_with_done(bufD,MsgCode::DONE); code_nosize.setCode(MsgCode::DONE); CPPUNIT_ASSERT( code_size.codeSize() == 4 ); CPPUNIT_ASSERT( code_size.totalSize() == sz ); CPPUNIT_ASSERT( code_with_init.getCode() == MsgCode::INIT ); CPPUNIT_ASSERT( code_with_event.getCode() == MsgCode::EVENT ); CPPUNIT_ASSERT( code_with_done.getCode() == MsgCode::DONE ); CPPUNIT_ASSERT( code_nosize.getCode() == MsgCode::DONE ); }
void code_at_put(int bci, Bytecodes::Code code) { Bytecodes::check(code); assert(0 <= bci && bci < code_size(), "valid bci"); address bcp = _code + bci; *bcp = code; }
int main (int argc, char *argv[]) { FILE *input1, *input2, *saida, *output; DEFINITION_TABLE_CELL *aux, *head; int fator_corretivo; if (argc < 4) { printf ("Faltam argumentos para o programa.\n"); return 0; } /*Abre os arquivos de entrada de dados, independente da terminaçao .o*/ input1 = open_sourcefile(argv[1]); input2 = open_sourcefile(argv[2]); output = open_targetfile(argv[3]); saida = fopen(TEMPORARY_FILE, "w+"); /*Se algum arquivo não abrir, temos um problema*/ if (input1 == NULL || input2 == NULL || output == NULL || saida == NULL){ printf ("Não foi possivel aprir algum arguivo.\n"); return 0; } /*Apaga possíveis espaços no fim do arquivo que me dão uma dor de cabeça enorme*/ apaga_trailing_space(input1); apaga_trailing_space(input2); /*Calcula o fator corretivo para deslocar o segundo arquivo*/ fator_corretivo = code_size(input1); if (debug1) printf ("Fator corretivo: %d\n", fator_corretivo); /*Se os arquivos forem independentes*/ if (precisa_ligar(input1) && (precisa_ligar(input2))) { /*Monta a primeira parte da tabela de definições */ head = monta_def_table(input1, input2, fator_corretivo); /*Comentário para acompanhar a tabela de definições 1*/ if (debug1) { printf ("\nTABELA DE DEFINICOES\n"); for (aux = head; aux != NULL; aux = aux->prox) printf ("ROTULO: '%s'\t'END: '%d'\n", aux->rotulo, aux->end); } /*COPIAR O CODIGO 1*/ goto_code(input1); copy_text(input1, saida); /*COPIA COM FATOR DE CORREÇÃO O CÓDIGO 2*/ goto_code(input2); copy_adjust_text (input2, saida, fator_corretivo); /*ESCREVE NO ARQUIVO TEMPORÁRIO, REMOVE O ' ' NO FIM QUE CAUSA PROBLEMAS*/ fclose(saida); saida = fopen(TEMPORARY_FILE, "r+"); apaga_trailing_space(saida); /*AGORA TENHO QUE AJUSTAR AS REFERÊNCIAS CRUZADAS*/ referencias_cruzadas(input1, input2, saida, output, head, fator_corretivo); } apaga_trailing_space(output); fclose(input1); fclose(input2); fclose(saida); fclose(output); remove(TEMPORARY_FILE); return 0; }
void get_code(char* buf) { std::memcpy(buf, &native_code[0], code_size()); }
// return the total size of relocation information, plus indexes, in nmethod int reloc_size() const { return RelocIterator::locs_and_index_size(code_size(), locs_size()); }