void Thread::start(JVM_SINGLE_ARG_TRAPS) { UsingFastOops fast_oops; ThreadObj::Fast receiver = thread_obj(); InstanceClass::Fast thread_class = receiver.blueprint(); // Find the 'run' method to invoke Method::Fast run_method = thread_class().lookup_method(Symbols::run_name(), Symbols::void_signature()); if (run_method.is_null()) { #ifndef PRODUCT tty->print_cr("Error: run method not found in "); thread_class.print(); tty->cr(); #endif JVM_FATAL(run_method_not_found); } // Setup execution entry EntryActivation::Fast run_entry = Universe::new_entry_activation(&run_method, 1 JVM_CHECK); run_entry().obj_at_put(0, &receiver); append_pending_entry(&run_entry); Scheduler::start(this JVM_NO_CHECK_AT_BOTTOM); }
static void update_fwd( bdescr *blocks ) { StgPtr p; bdescr *bd; StgInfoTable *info; bd = blocks; // cycle through all the blocks in the step for (; bd != NULL; bd = bd->link) { p = bd->start; // linearly scan the objects in this block while (p < bd->free) { ASSERT(LOOKS_LIKE_CLOSURE_PTR(p)); info = get_itbl((StgClosure *)p); p = thread_obj(info, p); } } }
void force_terminated(Thread* thread) { ThreadObj::Raw thread_obj = thread->thread_obj(); thread_obj().set_terminated(); }
bool generateDistanceFields(void) { if(FLAGS_df_list.empty()) { return false; } if (!boost::filesystem::exists(FLAGS_df_list)) { return false; } std::vector<DFItem> df_list; std::ifstream fin(FLAGS_df_list); std::string source, target; int resolution; std::set<std::string> folder_set; while (fin >> source >> resolution >> target) { df_list.push_back(std::make_tuple(source, resolution, target)); std::string folder = boost::filesystem::path(target).parent_path().string(); if(folder_set.find(folder) == folder_set.end()) { if (!boost::filesystem::exists(folder)) { boost::filesystem::create_directories(folder); folder_set.insert(folder); } } } LOG(INFO) << df_list.size() << " items to be processed!" << std::endl; if(!FLAGS_skip_converting) { int step = 100; for (int i = 0, i_end = df_list.size(); i < i_end; i ++) { const std::string filename_df = std::get<2>(df_list[i]); boost::filesystem::path path(filename_df); std::string filename_pcd = path.parent_path().string()+"/"+path.stem().string()+".pcd"; osg::ref_ptr <PointCloud> point_cloud(new PointCloud); if(point_cloud->load(filename_pcd)) { LOG(INFO) << "Skipping generating " << filename_pcd << " as it exists and reads well..." << std::endl; continue; } const std::string filename_mesh = std::get<0>(df_list[i]); LOG(INFO) << "Converting " << filename_mesh << " into point cloud..." << std::endl; osg::ref_ptr <MeshModel> mesh_model(new MeshModel); if(!mesh_model->load(filename_mesh)) { LOG(ERROR) << "Reading " << filename_mesh << " failed! Skipping it..." << std::endl; continue; } point_cloud->data()->clear(); double grid_size = mesh_model->sampleScan(point_cloud->data(), 100, 0.0); point_cloud->buildTree(); point_cloud->voxelGridFilter(grid_size/2, true); point_cloud->save(filename_pcd); if ((i+1)%step == 0) { LOG(INFO) << "Converted " << (i+1) << " items! (total item number: " << i_end << ")" << std::endl; } } } if (!FLAGS_skip_generation) { unsigned int n = std::thread::hardware_concurrency()-4; LOG(INFO) << n << " threads will be used!" << std::endl; std::vector<std::thread> threads; for (unsigned int i = 0; i < n; ++ i) { std::thread thread_obj(generateDistanceField, df_list, n, i); threads.push_back(std::move(thread_obj)); } for (unsigned int i = 0; i < n; ++ i) { threads[i].join(); } LOG(INFO) << "Distance field generation done!" << std::endl; } return true; }
static void update_fwd_compact( bdescr *blocks ) { StgPtr p, q, free; #if 0 StgWord m; #endif bdescr *bd, *free_bd; StgInfoTable *info; nat size; StgWord iptr; bd = blocks; free_bd = blocks; free = free_bd->start; // cycle through all the blocks in the step for (; bd != NULL; bd = bd->link) { p = bd->start; while (p < bd->free ) { while ( p < bd->free && !is_marked(p,bd) ) { p++; } if (p >= bd->free) { break; } #if 0 next: m = * ((StgPtr)bd->u.bitmap + ((p - bd->start) / (BITS_IN(StgWord)))); m >>= ((p - bd->start) & (BITS_IN(StgWord) - 1)); while ( p < bd->free ) { if ((m & 1) == 0) { m >>= 1; p++; if (((StgWord)p & (sizeof(W_) * BITS_IN(StgWord))) == 0) { goto next; } else { continue; } } #endif // Problem: we need to know the destination for this cell // in order to unthread its info pointer. But we can't // know the destination without the size, because we may // spill into the next block. So we have to run down the // threaded list and get the info ptr first. // // ToDo: one possible avenue of attack is to use the fact // that if (p&BLOCK_MASK) >= (free&BLOCK_MASK), then we // definitely have enough room. Also see bug #1147. iptr = get_threaded_info(p); info = INFO_PTR_TO_STRUCT(UNTAG_CLOSURE((StgClosure *)iptr)); q = p; p = thread_obj(info, p); size = p - q; if (free + size > free_bd->start + BLOCK_SIZE_W) { // unset the next bit in the bitmap to indicate that // this object needs to be pushed into the next // block. This saves us having to run down the // threaded info pointer list twice during the next pass. unmark(q+1,bd); free_bd = free_bd->link; free = free_bd->start; } else { ASSERT(is_marked(q+1,bd)); } unthread(q,(StgWord)free + GET_CLOSURE_TAG((StgClosure *)iptr)); free += size; #if 0 goto next; #endif } } }
/* * void nativeStart(Object [] startupState) * where startupState contains the following: * String classname * String [] args * String [][] context * * Note: all objects passed in parameters belongs to the new isolate * and no copy are necessary. See comments in com.sun.cldc.isolate.Isolate. */ void Java_com_sun_cldc_isolate_Isolate_nativeStart(JVM_SINGLE_ARG_TRAPS) { Thread::Raw saved; bool has_exception = false; const int id = Task::allocate_task_id(JVM_SINGLE_ARG_CHECK); { UsingFastOops fast_oops; IsolateObj::Fast isolate = GET_PARAMETER_AS_OOP(0); ObjectHeap::set_task_memory_quota(id, isolate().memory_reserve(), isolate().memory_limit() JVM_CHECK); const int prev = ObjectHeap::on_task_switch( id ); saved = Task::create_task(id, &isolate JVM_NO_CHECK); ObjectHeap::on_task_switch( prev ); if( saved.is_null() ) { ObjectHeap::reset_task_memory_usage(id); Task::cleanup_unstarted_task(id); isolate().terminate(-1 JVM_NO_CHECK_AT_BOTTOM); return; } } // save current thread pointer, no non-raw handles please! Thread::Raw current = Thread::current(); Thread::set_current(&saved); { // handles ok now UsingFastOops fast_oops; Thread::Fast orig = ¤t(); Thread::Fast t = &saved(); // IMPL_NOTE: SHOULDN'T WE DO SOMETHING HERE IF THERE IS SOME EXCEPTION // RELATED TO STARTUP FAILURE (i.e., reclaim the task's id and // proceed to task termination cleanup, including sending of // isolate events) Task::start_task(&t JVM_NO_CHECK); has_exception = (CURRENT_HAS_PENDING_EXCEPTION != NULL); current = orig; // GC may have happened. Reload. saved = t; // GC may have happened. Reload. } // we set the current thread back to the original so that the C interpreter // will switch threads correctly. The new thread/task is set to be the // next thread/task to run when switch_thread is called a few instructions // from now. Thread::set_current(¤t); if (has_exception) { UsingFastOops fast_oops; // new isolate got an exception somewhere during start_task(). The isolate // may not be able to handle the exception since we don't know at which // point it got the exception. Some classes may not be initialized, // task mirrors may not be setup etc. We just tear down the new isolate // and return an exception to the parent. Task::Fast task = Task::get_task(id); IsolateObj::Fast isolate = GET_PARAMETER_AS_OOP(0); Thread::Fast thrd = &saved(); GUARANTEE(!task.is_null(), "Task should not be null at this point"); task().set_status(Task::TASK_STOPPED); task().set_thread_count(0); isolate().terminate(-1 JVM_NO_CHECK); saved = thrd; // GC may have happened. Reload. } if (has_exception) { // Convoluted dance here. Child isolate failed to start // We check the type of exception // if (exception == oome) // throw oome to parent // else if (exception == isolateresourceerror) // throw IsolateResourceError to parent // else // throw java.lang.Error to parent // Make sure we don't have any handles to child objects before // calling Task::cleanup_terminated_task() // UsingFastOops fast_oops; Thread::Fast thrd = &saved(); JavaOop::Fast exception = thrd().noncurrent_pending_exception(); String::Fast str; { ThreadObj::Raw thread_obj = thrd().thread_obj(); // Mark thread as terminated even though it never really started if (!thread_obj.is_null()) { thread_obj().set_terminated(); } } Scheduler::terminate(&thrd JVM_NO_CHECK); thrd.set_null(); // thrd handle has to be disposed here JavaOop::Fast new_exception = Universe::out_of_memory_error_instance(); JavaClass::Fast exception_class = exception().blueprint(); // oome class *must* be loaded in parent, how can it not be? InstanceClass::Fast oome_class = SystemDictionary::resolve(Symbols::java_lang_OutOfMemoryError(), ErrorOnFailure JVM_NO_CHECK); InstanceClass::Fast ire_class = SystemDictionary::resolve(Symbols::com_sun_cldc_isolate_IsolateResourceError(), ErrorOnFailure JVM_NO_CHECK); if( oome_class.not_null() && !oome_class.equals(&exception_class) && ire_class.not_null() ) { new_exception = Throw::allocate_exception( ire_class.equals(&exception_class) ? Symbols::com_sun_cldc_isolate_IsolateResourceError() : Symbols::java_lang_Error(), &str JVM_NO_CHECK); } exception_class.set_null(); // cleared handles to child objects exception.set_null(); // Task::cleanup_terminated_task(id JVM_NO_CHECK); Thread::set_current_pending_exception(&new_exception); } }