< prev index next >

src/hotspot/share/interpreter/interpreterRuntime.cpp

Print this page




1100 IRT_END
1101 
1102 
1103 IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
1104   // We used to need an explict preserve_arguments here for invoke bytecodes. However,
1105   // stack traversal automatically takes care of preserving arguments for invoke, so
1106   // this is no longer needed.
1107 
1108   // IRT_END does an implicit safepoint check, hence we are guaranteed to block
1109   // if this is called during a safepoint
1110 
1111   if (JvmtiExport::should_post_single_step()) {
1112     // We are called during regular safepoints and when the VM is
1113     // single stepping. If any thread is marked for single stepping,
1114     // then we may have JVMTI work to do.
1115     LastFrameAccessor last_frame(thread);
1116     JvmtiExport::at_single_stepping_point(thread, last_frame.method(), last_frame.bcp());
1117   }
1118 IRT_END
1119 






















































































































































1120 IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
1121 ConstantPoolCacheEntry *cp_entry))
1122 
1123   // check the access_flags for the field in the klass
1124 
1125   InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
1126   int index = cp_entry->field_index();
1127   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
1128 
1129   bool is_static = (obj == NULL);
1130   HandleMark hm(thread);
1131 
1132   Handle h_obj;
1133   if (!is_static) {
1134     // non-static field accessors have an object, but we need a handle
1135     h_obj = Handle(thread, obj);
1136   }
1137   InstanceKlass* cp_entry_f1 = InstanceKlass::cast(cp_entry->f1_as_klass());
1138   jfieldID fid = jfieldIDWorkaround::to_jfieldID(cp_entry_f1, cp_entry->f2_as_index(), is_static);
1139   LastFrameAccessor last_frame(thread);




1100 IRT_END
1101 
1102 
1103 IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
1104   // We used to need an explict preserve_arguments here for invoke bytecodes. However,
1105   // stack traversal automatically takes care of preserving arguments for invoke, so
1106   // this is no longer needed.
1107 
1108   // IRT_END does an implicit safepoint check, hence we are guaranteed to block
1109   // if this is called during a safepoint
1110 
1111   if (JvmtiExport::should_post_single_step()) {
1112     // We are called during regular safepoints and when the VM is
1113     // single stepping. If any thread is marked for single stepping,
1114     // then we may have JVMTI work to do.
1115     LastFrameAccessor last_frame(thread);
1116     JvmtiExport::at_single_stepping_point(thread, last_frame.method(), last_frame.bcp());
1117   }
1118 IRT_END
1119 
1120 // all the continuation methods read the current continuation from the thread.
1121 
1122 
1123 static bool freeze_continuation(JavaThread* thread, oop cont, address _fp, address _sp, address _pc) {
1124   HandleMark hm(thread);
1125 
1126   tty->print_cr("AA 0000 %p %p %p", _pc, _fp, _sp);
1127 
1128   intptr_t* bottom = (intptr_t*)java_lang_Continuation::entrySP(cont); // watch for off-by-n
1129   intptr_t* top = (intptr_t*)_sp;
1130   int size = (bottom - top) * sizeof(intptr_t); // in bytes
1131 
1132   tty->print_cr("size: %d", size);
1133 
1134   Handle conth(thread, cont);
1135   JavaCallArguments args;
1136   args.push_oop(conth);
1137   args.push_int(size);
1138   JavaValue result(T_VOID);
1139   JavaCalls::call_virtual(&result, SystemDictionary::Continuation_klass(), vmSymbols::getStack_name(), vmSymbols::continuationGetStack_signature(), &args, thread);
1140   assert(java_lang_Continuation::stack_size(cont) >= size, "sanity check");
1141 
1142   int lastSenderSP = java_lang_Continuation::lastSenderSP(cont);
1143   int* hstack = (int*)java_lang_Continuation::stack_base(cont);
1144   
1145   address limit = (address)(hstack + lastSenderSP - 1); // this is the last byte, inclusive, we'll write to
1146   assert(limit - (address)hstack >= size, "sanity check");
1147   intptr_t* target = (intptr_t*)(limit - size);
1148 
1149   // set lastSenderSP
1150   
1151   ResourceMark rm(thread); // for vframes/symbols -- debug only
1152   RegisterMap map(thread, false);
1153 
1154   frame f(_sp, _fp, _pc);
1155   address source = _sp;
1156 
1157   while(true) {
1158     tty->print_cr("= Frame: fp: %p sp: %p pc: %p", f.fp(), f.sp(), f.pc());
1159     os::print_location(tty, *(intptr_t*)((address)f.fp() + frame::return_addr_offset));
1160     os::print_location(tty, (intptr_t)f.fp());
1161     os::print_location(tty, (intptr_t)f.sp());
1162     os::print_location(tty, *(intptr_t*)f.pc(), true);
1163 
1164     intptr_t* sp = f.sp();
1165     intptr_t* fp = f.fp();
1166 
1167     if (fp < bottom) {// I test FP because I want to print one more frame
1168       tty->print_cr("Found entry frame: %s", f.interpreter_frame_method()->name()->as_C_string());
1169       break;
1170     }
1171 
1172     bool is_interpreted = f.is_interpreted_frame();
1173     bool is_compiled = f.is_compiled_frame();
1174 
1175     if (is_interpreted) {
1176       tty->print_cr("Frame: %s", f.interpreter_frame_method()->name()->as_C_string());
1177 
1178       if (f.interpreter_frame_monitor_end() < f.interpreter_frame_monitor_begin()) {
1179         // pinned by monitors. Clear data copied so far from continuation.
1180         assert(false, "Monitors held -- unsupported");
1181         return false;
1182       }
1183     } else if (f.is_native_frame()) {
1184       // pinned; call continuation's pinned handler method. Clear data copied so far from continuation.
1185       assert(false, "Native frame -- unsupported");
1186       return false;
1187     }
1188 
1189     int fpoffset = fp - sp;
1190 
1191     f = f.sender(&map);
1192 
1193     int fsize = (f.sp() - sp)*sizeof(intptr_t);
1194 
1195     Copy::conjoint_memory_atomic(source, target, fsize);
1196 
1197     if (is_interpreted) {
1198       // patch
1199       intptr_t* hfp = target + fpoffset;
1200       tty->print_cr("hfp: %p", (void*)*hfp);
1201 
1202       // relativize pointers
1203       // *(hfp + frame::link_offset) = *(hfp + frame::link_offset) - (hfp + frame::link_offset);
1204       // *(hfp + frame::interpreter_frame_sender_sp_offset) = *(hfp + frame::interpreter_frame_sender_sp_offset) - (hfp + frame::interpreter_frame_sender_sp_offset);
1205     } else {
1206       assert(false, "Compiled frame -- unsupported");
1207     }
1208     
1209     source += fsize;
1210     target += fsize;
1211 
1212     assert(source == (address)f.sp(), "sanity");
1213   }
1214   return true;
1215 }
1216 // returns the continuation yielding (based on context), or NULL for failure (due to pinning)
1217 // it freezes multiple continuations, depending on contex
1218 // it must set Continuation.stackSize
1219 // sets Continuation.lastFP/SP to relative indices
1220 IRT_ENTRY(void, InterpreterRuntime::freeze(JavaThread* thread, FrameInfo* fi, oop context))
1221   HandleMark hm(thread);
1222   oop cont = java_lang_Thread::continuation(thread->threadObj());
1223 
1224   tty->print_cr("freeze cont: %p", cont);
1225 
1226   if (false) {
1227     // while(cont.context != context)
1228     bool res = freeze_continuation(thread, cont, fi->fp, fi->sp, fi->pc);
1229     if (!res) {
1230       fi->fp = 0;
1231       fi->sp = 0;
1232       fi->pc = 0;
1233       return;
1234     }
1235   }
1236   
1237   java_lang_Thread::set_continuation(thread->threadObj(), cont);
1238   tty->print_cr("freeze cont3: %p", cont);
1239 
1240   fi->sp = java_lang_Continuation::entrySP(cont);
1241   fi->fp = java_lang_Continuation::entryFP(cont);
1242   fi->pc = java_lang_Continuation::entryPC(cont);
1243 IRT_END
1244 
1245 // patches the return address of the bottom-most frame returned to the return barrier codelet
1246 // returns the pc of the topmost frame, or 0 if no more frames (in fi)
1247 // or, maybe, doesn't patch the return adress if it's the last frame, so the last frame won't go through the return barrier
1248 void InterpreterRuntime::pop_and_thaw0(JavaThread* thread, FrameInfo* fi, int num_frames, bool pop) {
1249   HandleMark hm(thread);
1250   oop cont = java_lang_Thread::continuation(thread->threadObj());
1251   
1252   // fi->pc is the return address to patch
1253   // when copying nmethods, we need to check for them being made non-reentrant, in which case we need to deopt them
1254   // and turn them into interpreter frames.
1255 
1256   // if no more frames, jump to entry:
1257   fi->sp = java_lang_Continuation::entrySP(cont);
1258   fi->fp = java_lang_Continuation::entryFP(cont);
1259   fi->pc = java_lang_Continuation::entryPC(cont);
1260 }
1261 
1262 IRT_ENTRY(void, InterpreterRuntime::pop_and_thaw(JavaThread* thread, FrameInfo* fi, int num_frames))
1263   pop_and_thaw0(thread, fi, num_frames, true);
1264 IRT_END
1265 
1266 IRT_ENTRY(void, InterpreterRuntime::thaw(JavaThread* thread, FrameInfo* fi, int num_frames))
1267   pop_and_thaw0(thread, fi, num_frames, false);
1268 IRT_END
1269 
1270 IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
1271 ConstantPoolCacheEntry *cp_entry))
1272 
1273   // check the access_flags for the field in the klass
1274 
1275   InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
1276   int index = cp_entry->field_index();
1277   if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
1278 
1279   bool is_static = (obj == NULL);
1280   HandleMark hm(thread);
1281 
1282   Handle h_obj;
1283   if (!is_static) {
1284     // non-static field accessors have an object, but we need a handle
1285     h_obj = Handle(thread, obj);
1286   }
1287   InstanceKlass* cp_entry_f1 = InstanceKlass::cast(cp_entry->f1_as_klass());
1288   jfieldID fid = jfieldIDWorkaround::to_jfieldID(cp_entry_f1, cp_entry->f2_as_index(), is_static);
1289   LastFrameAccessor last_frame(thread);


< prev index next >