hotspot/src/share/vm/runtime/frame.cpp
changeset 5419 f2e8cc8c12ea
parent 4896 88b4193b82b0
child 5426 470c15eda401
equal deleted inserted replaced
5418:c4955cb6ed33 5419:f2e8cc8c12ea
   466 intptr_t* frame::interpreter_frame_local_at(int index) const {
   466 intptr_t* frame::interpreter_frame_local_at(int index) const {
   467   const int n = Interpreter::local_offset_in_bytes(index)/wordSize;
   467   const int n = Interpreter::local_offset_in_bytes(index)/wordSize;
   468   return &((*interpreter_frame_locals_addr())[n]);
   468   return &((*interpreter_frame_locals_addr())[n]);
   469 }
   469 }
   470 
   470 
   471 frame::Tag frame::interpreter_frame_local_tag(int index) const {
       
   472   const int n = Interpreter::local_tag_offset_in_bytes(index)/wordSize;
       
   473   return (Tag)(*interpreter_frame_locals_addr()) [n];
       
   474 }
       
   475 
       
   476 void frame::interpreter_frame_set_local_tag(int index, Tag tag) const {
       
   477   const int n = Interpreter::local_tag_offset_in_bytes(index)/wordSize;
       
   478   (*interpreter_frame_locals_addr())[n] = (intptr_t)tag;
       
   479 }
       
   480 
       
   481 intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const {
   471 intptr_t* frame::interpreter_frame_expression_stack_at(jint offset) const {
   482   const int i = offset * interpreter_frame_expression_stack_direction();
   472   const int i = offset * interpreter_frame_expression_stack_direction();
   483   const int n = ((i * Interpreter::stackElementSize()) +
   473   const int n = i * Interpreter::stackElementWords;
   484                  Interpreter::value_offset_in_bytes())/wordSize;
       
   485   return &(interpreter_frame_expression_stack()[n]);
   474   return &(interpreter_frame_expression_stack()[n]);
   486 }
       
   487 
       
   488 frame::Tag frame::interpreter_frame_expression_stack_tag(jint offset) const {
       
   489   const int i = offset * interpreter_frame_expression_stack_direction();
       
   490   const int n = ((i * Interpreter::stackElementSize()) +
       
   491                  Interpreter::tag_offset_in_bytes())/wordSize;
       
   492   return (Tag)(interpreter_frame_expression_stack()[n]);
       
   493 }
       
   494 
       
   495 void frame::interpreter_frame_set_expression_stack_tag(jint offset,
       
   496                                                        Tag tag) const {
       
   497   const int i = offset * interpreter_frame_expression_stack_direction();
       
   498   const int n = ((i * Interpreter::stackElementSize()) +
       
   499                  Interpreter::tag_offset_in_bytes())/wordSize;
       
   500   interpreter_frame_expression_stack()[n] = (intptr_t)tag;
       
   501 }
   475 }
   502 
   476 
   503 jint frame::interpreter_frame_expression_stack_size() const {
   477 jint frame::interpreter_frame_expression_stack_size() const {
   504   // Number of elements on the interpreter expression stack
   478   // Number of elements on the interpreter expression stack
   505   // Callers should span by stackElementWords
   479   // Callers should span by stackElementWords
   506   int element_size = Interpreter::stackElementWords();
   480   int element_size = Interpreter::stackElementWords;
   507   if (frame::interpreter_frame_expression_stack_direction() < 0) {
   481   if (frame::interpreter_frame_expression_stack_direction() < 0) {
   508     return (interpreter_frame_expression_stack() -
   482     return (interpreter_frame_expression_stack() -
   509             interpreter_frame_tos_address() + 1)/element_size;
   483             interpreter_frame_tos_address() + 1)/element_size;
   510   } else {
   484   } else {
   511     return (interpreter_frame_tos_address() -
   485     return (interpreter_frame_tos_address() -
   583   assert(is_interpreted_frame(), "Not an interpreted frame");
   557   assert(is_interpreted_frame(), "Not an interpreted frame");
   584   jint i;
   558   jint i;
   585   for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) {
   559   for (i = 0; i < interpreter_frame_method()->max_locals(); i++ ) {
   586     intptr_t x = *interpreter_frame_local_at(i);
   560     intptr_t x = *interpreter_frame_local_at(i);
   587     st->print(" - local  [" INTPTR_FORMAT "]", x);
   561     st->print(" - local  [" INTPTR_FORMAT "]", x);
   588     if (TaggedStackInterpreter) {
       
   589       Tag x = interpreter_frame_local_tag(i);
       
   590       st->print(" - local tag [" INTPTR_FORMAT "]", x);
       
   591     }
       
   592     st->fill_to(23);
   562     st->fill_to(23);
   593     st->print_cr("; #%d", i);
   563     st->print_cr("; #%d", i);
   594   }
   564   }
   595   for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) {
   565   for (i = interpreter_frame_expression_stack_size() - 1; i >= 0; --i ) {
   596     intptr_t x = *interpreter_frame_expression_stack_at(i);
   566     intptr_t x = *interpreter_frame_expression_stack_at(i);
   597     st->print(" - stack  [" INTPTR_FORMAT "]", x);
   567     st->print(" - stack  [" INTPTR_FORMAT "]", x);
   598     if (TaggedStackInterpreter) {
       
   599       Tag x = interpreter_frame_expression_stack_tag(i);
       
   600       st->print(" - stack tag [" INTPTR_FORMAT "]", x);
       
   601     }
       
   602     st->fill_to(23);
   568     st->fill_to(23);
   603     st->print_cr("; #%d", i);
   569     st->print_cr("; #%d", i);
   604   }
   570   }
   605   // locks for synchronization
   571   // locks for synchronization
   606   for (BasicObjectLock* current = interpreter_frame_monitor_end();
   572   for (BasicObjectLock* current = interpreter_frame_monitor_end();
   948         oops_interpreted_arguments_do(signature, has_receiver, f);
   914         oops_interpreted_arguments_do(signature, has_receiver, f);
   949       }
   915       }
   950     }
   916     }
   951   }
   917   }
   952 
   918 
   953   if (TaggedStackInterpreter) {
   919   InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f);
   954     // process locals & expression stack
   920 
   955     InterpreterOopMap *mask = NULL;
   921   // process locals & expression stack
   956 #ifdef ASSERT
   922   InterpreterOopMap mask;
   957     InterpreterOopMap oopmap_mask;
   923   if (query_oop_map_cache) {
   958     OopMapCache::compute_one_oop_map(m, bci, &oopmap_mask);
   924     m->mask_for(bci, &mask);
   959     mask = &oopmap_mask;
       
   960 #endif // ASSERT
       
   961     oops_interpreted_locals_do(f, max_locals, mask);
       
   962     oops_interpreted_expressions_do(f, signature, has_receiver,
       
   963                                     m->max_stack(),
       
   964                                     max_locals, mask);
       
   965   } else {
   925   } else {
   966     InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f);
   926     OopMapCache::compute_one_oop_map(m, bci, &mask);
   967 
   927   }
   968     // process locals & expression stack
   928   mask.iterate_oop(&blk);
   969     InterpreterOopMap mask;
   929 }
   970     if (query_oop_map_cache) {
   930 
   971       m->mask_for(bci, &mask);
       
   972     } else {
       
   973       OopMapCache::compute_one_oop_map(m, bci, &mask);
       
   974     }
       
   975     mask.iterate_oop(&blk);
       
   976   }
       
   977 }
       
   978 
       
   979 
       
   980 void frame::oops_interpreted_locals_do(OopClosure *f,
       
   981                                       int max_locals,
       
   982                                       InterpreterOopMap *mask) {
       
   983   // Process locals then interpreter expression stack
       
   984   for (int i = 0; i < max_locals; i++ ) {
       
   985     Tag tag = interpreter_frame_local_tag(i);
       
   986     if (tag == TagReference) {
       
   987       oop* addr = (oop*) interpreter_frame_local_at(i);
       
   988       assert((intptr_t*)addr >= sp(), "must be inside the frame");
       
   989       f->do_oop(addr);
       
   990 #ifdef ASSERT
       
   991     } else {
       
   992       assert(tag == TagValue, "bad tag value for locals");
       
   993       oop* p = (oop*) interpreter_frame_local_at(i);
       
   994       // Not always true - too bad.  May have dead oops without tags in locals.
       
   995       // assert(*p == NULL || !(*p)->is_oop(), "oop not tagged on interpreter locals");
       
   996       assert(*p == NULL || !mask->is_oop(i), "local oop map mismatch");
       
   997 #endif // ASSERT
       
   998     }
       
   999   }
       
  1000 }
       
  1001 
       
  1002 void frame::oops_interpreted_expressions_do(OopClosure *f,
       
  1003                                       symbolHandle signature,
       
  1004                                       bool has_receiver,
       
  1005                                       int max_stack,
       
  1006                                       int max_locals,
       
  1007                                       InterpreterOopMap *mask) {
       
  1008   // There is no stack no matter what the esp is pointing to (native methods
       
  1009   // might look like expression stack is nonempty).
       
  1010   if (max_stack == 0) return;
       
  1011 
       
  1012   // Point the top of the expression stack above arguments to a call so
       
  1013   // arguments aren't gc'ed as both stack values for callee and callee
       
  1014   // arguments in callee's locals.
       
  1015   int args_size = 0;
       
  1016   if (!signature.is_null()) {
       
  1017     args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
       
  1018   }
       
  1019 
       
  1020   intptr_t *tos_addr = interpreter_frame_tos_at(args_size);
       
  1021   assert(args_size != 0 || tos_addr == interpreter_frame_tos_address(), "these are same");
       
  1022   intptr_t *frst_expr = interpreter_frame_expression_stack_at(0);
       
  1023   // In case of exceptions, the expression stack is invalid and the esp
       
  1024   // will be reset to express this condition. Therefore, we call f only
       
  1025   // if addr is 'inside' the stack (i.e., addr >= esp for Intel).
       
  1026   bool in_stack;
       
  1027   if (interpreter_frame_expression_stack_direction() > 0) {
       
  1028     in_stack = (intptr_t*)frst_expr <= tos_addr;
       
  1029   } else {
       
  1030     in_stack = (intptr_t*)frst_expr >= tos_addr;
       
  1031   }
       
  1032   if (!in_stack) return;
       
  1033 
       
  1034   jint stack_size = interpreter_frame_expression_stack_size() - args_size;
       
  1035   for (int j = 0; j < stack_size; j++) {
       
  1036     Tag tag = interpreter_frame_expression_stack_tag(j);
       
  1037     if (tag == TagReference) {
       
  1038       oop *addr = (oop*) interpreter_frame_expression_stack_at(j);
       
  1039       f->do_oop(addr);
       
  1040 #ifdef ASSERT
       
  1041     } else {
       
  1042       assert(tag == TagValue, "bad tag value for stack element");
       
  1043       oop *p = (oop*) interpreter_frame_expression_stack_at((j));
       
  1044       assert(*p == NULL || !mask->is_oop(j+max_locals), "stack oop map mismatch");
       
  1045 #endif // ASSERT
       
  1046     }
       
  1047   }
       
  1048 }
       
  1049 
   931 
  1050 void frame::oops_interpreted_arguments_do(symbolHandle signature, bool has_receiver, OopClosure* f) {
   932 void frame::oops_interpreted_arguments_do(symbolHandle signature, bool has_receiver, OopClosure* f) {
  1051   InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
   933   InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
  1052   finder.oops_do();
   934   finder.oops_do();
  1053 }
   935 }
  1304   methodOop m   = interpreter_frame_method();
  1186   methodOop m   = interpreter_frame_method();
  1305   int       bci = interpreter_frame_bci();
  1187   int       bci = interpreter_frame_bci();
  1306 
  1188 
  1307   int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();
  1189   int max_locals = m->is_native() ? m->size_of_parameters() : m->max_locals();
  1308 
  1190 
  1309   if (TaggedStackInterpreter) {
  1191   // process dynamic part
  1310     InterpreterOopMap *mask = NULL;
  1192   InterpreterFrameClosure value_blk(this, max_locals, m->max_stack(),
  1311 #ifdef ASSERT
  1193                                     &_check_value);
  1312     InterpreterOopMap oopmap_mask;
  1194   InterpreterFrameClosure   oop_blk(this, max_locals, m->max_stack(),
  1313     methodHandle method(thread, m);
  1195                                     &_check_oop  );
  1314     OopMapCache::compute_one_oop_map(method, bci, &oopmap_mask);
  1196   InterpreterFrameClosure  dead_blk(this, max_locals, m->max_stack(),
  1315     mask = &oopmap_mask;
  1197                                     &_zap_dead   );
  1316 #endif // ASSERT
  1198 
  1317     oops_interpreted_locals_do(&_check_oop, max_locals, mask);
  1199   // get frame map
  1318   } else {
  1200   InterpreterOopMap mask;
  1319     // process dynamic part
  1201   m->mask_for(bci, &mask);
  1320     InterpreterFrameClosure value_blk(this, max_locals, m->max_stack(),
  1202   mask.iterate_all( &oop_blk, &value_blk, &dead_blk);
  1321                                       &_check_value);
       
  1322     InterpreterFrameClosure   oop_blk(this, max_locals, m->max_stack(),
       
  1323                                       &_check_oop  );
       
  1324     InterpreterFrameClosure  dead_blk(this, max_locals, m->max_stack(),
       
  1325                                       &_zap_dead   );
       
  1326 
       
  1327     // get frame map
       
  1328     InterpreterOopMap mask;
       
  1329     m->mask_for(bci, &mask);
       
  1330     mask.iterate_all( &oop_blk, &value_blk, &dead_blk);
       
  1331   }
       
  1332 }
  1203 }
  1333 
  1204 
  1334 
  1205 
  1335 void frame::zap_dead_compiled_locals(JavaThread* thread, const RegisterMap* reg_map) {
  1206 void frame::zap_dead_compiled_locals(JavaThread* thread, const RegisterMap* reg_map) {
  1336 
  1207