void GraalCompiler::bootstrap() { JavaThread* THREAD = JavaThread::current(); _bootstrapping = true; ResourceMark rm; HandleMark hm; if (PrintBootstrap) { tty->print("Bootstrapping Graal"); } jlong start = os::javaTimeMillis(); Array<Method*>* objectMethods = InstanceKlass::cast(SystemDictionary::Object_klass())->methods(); // Initialize compile queue with a selected set of methods. int len = objectMethods->length(); for (int i = 0; i < len; i++) { methodHandle mh = objectMethods->at(i); if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) { ResourceMark rm; int hot_count = 10; // TODO: what's the appropriate value? CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, "bootstrap", THREAD); } } int qsize; jlong sleep_time = 1000; int z = 0; do { os::sleep(THREAD, sleep_time, true); sleep_time = 100; qsize = CompileBroker::queue_size(CompLevel_full_optimization); if (PrintBootstrap) { while (z < (_methodsCompiled / 100)) { ++z; tty->print_raw("."); } } } while (qsize != 0); if (PrintBootstrap) { tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methodsCompiled); } _bootstrapping = false; }
ASObject* Vector::generator(TemplatedClass<Vector>* o_class, ASObject* const* args, const unsigned int argslen) { assert_and_throw(argslen == 1); assert_and_throw(args[0]->getClass()); assert_and_throw(o_class->getTypes().size() == 1); Type* type = o_class->getTypes()[0]; if(args[0]->getClass() == Class<Array>::getClass()) { //create object without calling _constructor Vector* ret = o_class->getInstance(false,NULL,0); Array* a = static_cast<Array*>(args[0]); for(unsigned int i=0;i<a->size();++i) { ASObject* obj = a->at(i).getPtr(); obj->incRef(); //Convert the elements of the array to the type of this vector ret->vec.push_back( type->coerce(obj) ); } return ret; } else if(args[0]->getClass()->getTemplate() == Template<Vector>::getTemplate()) { Vector* arg = static_cast<Vector*>(args[0]); //create object without calling _constructor Vector* ret = o_class->getInstance(false,NULL,0); for(auto i = arg->vec.begin(); i != arg->vec.end(); ++i) { (*i)->incRef(); ret->vec.push_back( type->coerce(*i) ); } return ret; } else { throw Class<ArgumentError>::getInstanceS("global Vector() function takes Array or Vector"); } }
void Mesh::setHash(Hash* hash) { if(hash->contains("material")) { setupMaterial(hash->getValue("material")->getHash()); } if(hash->contains("verticies")) { Array* verts = hash->getValue("verticies")->getArray(); for(unsigned int i = 0; i < verts->size(); i++) { Array* vert = verts->at(i)->getArray(); addPoint(new Point3D(vert->at(0)->getDouble(), vert->at(1)->getDouble(), vert->at(2)->getDouble())); } } if(hash->contains("faces")) { Array* faces = hash->getValue("faces")->getArray(); for(unsigned int i = 0; i < faces->size(); i++) { Array* f = faces->at(i)->getArray(); addFace(f->at(0)->getInteger(), f->at(1)->getInteger(), f->at(2)->getInteger()); } calculateNormals(); } }
int main() { int yourMark = 1; /* 2-es */ Array<int, 5> ai; Array<double, 3> ad(2.0); const Array<char, 2> ac('a'); if ('a' == ac.at(0)) yourMark = ac.size(); /**/ /* 3-as */ const Array<double, 3> cad = ad; ai[0] = ai[1] = ai[2] = 3; ai[3] = ai[4] = 1; const Array<int, 5> cai = ai; yourMark = cai[0]; /**/ /* 4-es */ std::list<int> ld; ld.push_back(ai[0]); ld.push_back(ai[3]); std::deque<int> di (ld.begin(), ld.end()); di[1] = 42; Print<int> p1 = for_each_if(ld.begin(), ld.end(), Less<int>(2), Print<int>()); Print<int> p2 = for_each_if(di.begin(), di.end(), Less<int>(10), Print<int>()); if (1 == p1.get() && 3 == p2.get()) yourMark = p1.get() + p2.get(); /**/ /* 5-os */ Print<double> p3 = for_each_if(cad.begin(), cad.end(), Less<double>(2.3), Print<double>()); if ( 6.0 == p3.get()) yourMark = ai.size(); /**/ std::cout << "Your mark is " << yourMark << std::endl; return 0; }
void merge_sort(Array<Item>& a, int_t left, int_t right, ResultArray<Item>& result, int_t result_offset, TmpArray<Item>& tmp_array, int_t tmp_offset, const Compare_fct& compare) { if (left == right) { return; } if (left + 1 == right) { result.at(result_offset) = a.at(left); return; } using controller_type = pasl::pctl::granularity::controller_holder<merge_sort_file, 1, Array<Item>, ResultArray<Item>, TmpArray<Item>, Compare_fct>; pasl::pctl::granularity::cstmt(controller_type::controller, [&] { return right - left; }, [&] { int_t mid = (left + right) >> 1; pasl::pctl::granularity::fork2([&] { merge_sort(a, left, mid, result, result_offset, tmp_array, tmp_offset, compare); }, [&] { merge_sort(a, mid, right, result, result_offset + mid - left, tmp_array, tmp_offset + mid - left, compare); }); merge(result, left, mid, result, mid, right, tmp_array, tmp_offset, compare); pasl::pctl::range::parallel_for(0, right - left, [&] (int_t l, int_t r) { return r - l; }, [&] (int_t i) { result.at(result_offset + i) = tmp_array.at(tmp_offset + i); }, [&] (int_t l, int_t r) { std::copy(tmp_array.begin() + tmp_offset + l, tmp_array.begin() + tmp_offset + r, result.begin() + result_offset + l); }); }, [&] {
int main (void) { Array array (20); for (int i = 0; i < array.size (); ++i) array.at (i) = i; print (array); /* Array a1 (5); a1.at (0) = 10; a1.at (1) = 20; a1.at (2) = 30; a1.at (3) = 40; a1.at (4) = 50; print (a1); Array a2 = a1; print (a2); */ Array* a1 = new Array (5); a1->at (0) = 10; a1->at (1) = 20; a1->at (2) = 30; a1->at (3) = 40; a1->at (4) = 50; print (*a1); // Array* a2 = new Array (*a1); Array* a2 = new Array (5); *a2 = *a1; // (*a2).operator= (*a1) print (*a2); a2->at(0)++; print (*a1); print (*a2); *a2 = *a2; // (*a2).operator= (*a2) print (*a2); delete a2; delete a1; return 0; }
void ClassLoadingService::notify_class_unloaded(InstanceKlass* k) { DTRACE_CLASSLOAD_PROBE(unloaded, k, false); // Classes that can be unloaded must be non-shared _classes_unloaded_count->inc(); if (UsePerfData) { // add the class size size_t size = compute_class_size(k); _classbytes_unloaded->inc(size); // Compute method size & subtract from running total. // We are called during phase 1 of mark sweep, so it's // still ok to iterate through Method*s here. Array<Method*>* methods = k->methods(); for (int i = 0; i < methods->length(); i++) { _class_methods_size->inc(-methods->at(i)->size()); } } if (TraceClassUnloading) { ResourceMark rm; tty->print_cr("[Unloading class %s " INTPTR_FORMAT "]", k->external_name(), p2i(k)); } }
static void test_pod() { Array<unsigned> array; const size_t initial_capacity = 20, grow_capacity = 12, alignment = 4; UAllocTraits_t traits = {0}; MBED_HOSTTEST_ASSERT(array.init(initial_capacity, grow_capacity, traits, alignment)); // Start filling the array for (unsigned i = 0; i < initial_capacity; i ++ ) { array.push_back(i); } MBED_HOSTTEST_ASSERT(array.get_num_elements() == initial_capacity); for (unsigned i = 0; i < initial_capacity; i ++) { MBED_HOSTTEST_ASSERT(array[i] == i); } MBED_HOSTTEST_ASSERT(array.get_num_zones() == 1); // Add another element, this should trigger the creation of another zone array.push_back(1000); MBED_HOSTTEST_ASSERT(array.get_num_zones() == 2); MBED_HOSTTEST_ASSERT(array.get_num_elements() == initial_capacity + 1); // Fill the second zone too for (unsigned i = 1; i < grow_capacity; i ++) { array.push_back(1000 + i); } MBED_HOSTTEST_ASSERT(array.get_num_elements() == initial_capacity + grow_capacity); for (unsigned i = 0; i < grow_capacity; i ++) { MBED_HOSTTEST_ASSERT(array.at(i + initial_capacity) == 1000 + i); } MBED_HOSTTEST_ASSERT(array.get_num_zones() == 2); unsigned save_for_later = array[initial_capacity + grow_capacity - 1]; // Add yet another element, which should result in the creation of another zone array.push_back(10000); MBED_HOSTTEST_ASSERT(array[initial_capacity + grow_capacity] == 10000); MBED_HOSTTEST_ASSERT(array.get_num_zones() == 3); MBED_HOSTTEST_ASSERT(array.get_num_elements() == initial_capacity + grow_capacity + 1); // Remove the last element array.pop_back(); MBED_HOSTTEST_ASSERT(array.get_num_elements() == initial_capacity + grow_capacity); MBED_HOSTTEST_ASSERT(array[array.get_num_elements() - 1] == save_for_later); MBED_HOSTTEST_ASSERT(array.get_num_zones() == 3); // the array doesn't (yet?) shrink // Simple bubble sort test illustrating moving around elements in the array const size_t total = initial_capacity + grow_capacity; for (unsigned i = 0; i < total; i ++) { array.at(i) = total - i - 1; } for (unsigned i = 0; i < total - 1; i ++) { for (unsigned j = i + 1; j < total; j ++) { if (array[i] > array[j]) { unsigned temp = array[i]; array[i] = array[j]; array[j] = temp; } } } for (unsigned i = 0; i < total; i ++) { MBED_HOSTTEST_ASSERT(array[i] == i); } MBED_HOSTTEST_ASSERT(array.get_num_zones() == 3); }
bool CJson:: matchArray(const ValueP &value, const std::string &lhs, const std::string &rhs, Values &values) { if (isDebug()) std::cerr << "matchArray \'" << lhs << "\' \'" << rhs << "\'" << std::endl; if (! value->isArray()) { if (! isQuiet()) std::cerr << value->typeName() << " is not an array" << std::endl; return false; } Array *array = value->cast<Array>(); if (lhs[0] != '[' || lhs[lhs.size() - 1] != ']') return false; std::string range = lhs.substr(1, lhs.size() - 2); if (range == "?size") { Number *n = createNumber(array->size()); values.push_back(ValueP(n)); return true; } auto p = range.find(','); if (p != std::string::npos) { std::string match1 = range; std::string lhs1 = match1.substr(0, p); std::string rhs1 = match1.substr(p + 1); bool ok1, ok2; int i1 = CJson::stol(lhs1, ok1); int i2 = CJson::stol(rhs1, ok2); if (! ok1 || ! ok2) { if (! isQuiet()) std::cerr << "Invalid array indices '" << lhs1 << "', '" << rhs1 << "'" << std::endl; return false; } for (int i = i1; i <= i2 && i < int(array->size()); ++i) { ValueP value1 = array->at(i); if (rhs1 != "") matchValues(value1, i, rhs1, values); else values.push_back(value1); } } else if (range != "") { bool ok; int i1 = CJson::stol(range, ok); if (! ok) { if (! isQuiet()) std::cerr << "Invalid array index '" << lhs << "'" << std::endl; return false; } int i = 0; for (const auto &v : array->values()) { if (i == i1) { if (rhs != "") matchValues(v, i, rhs, values); else values.push_back(v); } ++i; } } else { int i = 0; for (const auto &v : array->values()) { if (rhs != "") matchValues(v, i, rhs, values); else values.push_back(v); ++i; } } return true; }
CouchFine::Array Database::createBulk( const CouchFine::Array& docs, CouchFine::fnCreateJSON_t fnCreateJSON ) { // I. —охраним документы. // »сключим из списка документов пол¤, начинающиес¤ с Mode::File::PREFIX // @todo optimize ƒелаетс¤ копи¤ 'docs'. ѕросадка производительности. Array preparedDocs; for (auto itr = docs.cbegin(); itr != docs.cend(); ++itr) { #ifdef _DEBUG const std::string& typeName = (*itr)->type().name(); auto t1 = *itr; auto t2 = *t1; #endif // #! ќшибка? ”бедитесь, что сюда не попал const-объект. Object* d = boost::any_cast< Object* >( **itr ); // просматриваем пол¤, ставл¤ем те, что без Mode::File::PREFIX Object obj; for (auto dtr = d->cbegin(); dtr != d->cend(); ++dtr) { const std::string& field = dtr->first; if ( !boost::starts_with( field, Mode::File::PREFIX() ) ) { // @todo optimize —обирать только ссылки? obj[ field ] = dtr->second; } } preparedDocs.push_back( typelib::json::cjv( obj ) ); } // for (auto itr = docs.cbegin(); itr != docs.cend(); ++itr) // @see http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API#Modify_Multiple_Documents_With_a_Single_Request Object o; o["docs"] = typelib::json::cjv( preparedDocs ); const std::string json = fnCreateJSON ? ( fnCreateJSON )( typelib::json::cjv( o ) ) : createJSON( typelib::json::cjv( o ) ); // @see http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API#Modify_Multiple_Documents_With_a_Single_Request assert( !name.empty() && "Store is don't initialized." ); const Variant var = comm.getData( "/" + name + "/_bulk_docs", "POST", json ); if ( hasError( var ) ) { std::cerr << "JSON: " << json << std::endl; std::cerr << "CouchFine::createBulk( const std::string& ) " << error( var ) << std::endl; throw CouchFine::Exception( "Unrecognized exception: " + error( var ) ); } const Array ra = boost::any_cast< Array >( *var ); // II. —охран¤ем файлы-вложени¤. // @todo ѕозволить сохран¤ть разные типы данных, не только plain/text. // @todo optimize —охран¤ть пол¤ документов и файлы в один запрос. for (auto itr = docs.cbegin(); itr != docs.cend(); ++itr) { const Object* d = boost::any_cast< Object* >( **itr ); for (auto dtr = d->cbegin(); dtr != d->cend(); ++dtr) { const std::string& field = dtr->first; if ( boost::starts_with( field, Mode::File::PREFIX() ) ) { // пор¤док следовани¤ - совпадает // инициируем здесь в расчЄте на то, что кол-во документов с // файлами-вложени¤ много меньше общего кол-ва в 'docs' const std::size_t i = std::distance( docs.cbegin(), itr ); const Object& ora = boost::any_cast< Object& >( *ra.at( i ) ); const std::string nameFile = boost::erase_first_copy( field, Mode::File::PREFIX() ); const std::string& dataFile = boost::any_cast< std::string& >( *dtr->second ); const uid_t& uidDoc = uid( ora ); assert( !uidDoc.empty() && "ќбнаружен пустой UID. Ќеожиданно..." ); const rev_t& revisionDoc = revision( ora ); assert( !revisionDoc.empty() && "ќбнаружена пуста¤ ревизи¤. Ќеожиданно..." ); /* - «аменено. —м. ниже. *this << Mode::File( name, data, uidDoc, revisionDoc ); */ /* - —оздать документ дешевле, чем тащить его из хранилища. —м. ниже. Document doc = getDocument( uidDoc ); */ Document doc( Database::comm, Database::name, uidDoc, "", revisionDoc ); const bool result = doc.addAttachment( nameFile, "text/plain", dataFile ); if ( !result ) { throw CouchFine::Exception( "Could not create attachment '" + nameFile + "' with data '" + dataFile + "'." ); } } // if ( boost::starts_with( field, Mode::File::PREFIX() ) ) } // for (auto dtr = d.cbegin(); dtr != d.cend(); ++dtr) } // for (auto itr = docs.cbegin(); itr != docs.cend(); ++itr) return ra; }
void print (Array const& array) { for (size_t i = 0; i < array.size (); ++i) cout << array.at (i) << ' '; cout << endl; }
u1 get_u1(TRAPS) { if (_data == NULL || _index >= _data->length()) { stackmap_format_error("access beyond the end of attribute", CHECK_0); } return _data->at(_index++); }
int ArchivePanel::pGetFindData( PluginPanelItem **pPanelItem, int* pItemsNumber, int OpMode ) { bool bSilent = OpMode & (OPM_SILENT|OPM_FIND); if ( m_bFirstTime ) { if ( m_pFormats.count() ) { int nResult = 0; if ( m_pFormats.count() > 1 && !bSilent) { FarMenu menu(_M(MOpenArchiveAs)); string strText; for (unsigned int i = 0; i < m_pFormats.count(); i++) { const ArchiveFormat* pFormat = m_pFormats[i]; strText.Format(_T("%s"), pFormat->GetName()); menu.Add(strText); } nResult = menu.Run(); } if ( nResult != -1 ) m_pArchive = m_pManager->OpenCreateArchive(m_pFormats[nResult], m_strFileName, this, Callback, false); if ( nResult == -1 ) return FALSE; } m_bFirstTime = false; } #pragma message("check if pArchive exists!!") if ( !m_pArchive->ReadArchiveItems() ) return FALSE; //??? в ¬ Ґв FALSE const ArchiveInfoItem* pInfoItems; m_nArchiveInfoItems = m_pArchive->GetArchiveInfo(m_bMultiVolume, &pInfoItems); if ( m_nArchiveInfoItems ) { m_pArchiveInfo = new InfoPanelLine[m_nArchiveInfoItems]; memset(m_pArchiveInfo, 0, sizeof(InfoPanelLine)*m_nArchiveInfoItems); for (int i = 0; i < m_nArchiveInfoItems; i++) { #ifdef UNICODE m_pArchiveInfo[i].Text = StrDuplicate(pInfoItems[i].lpName); m_pArchiveInfo[i].Data = StrDuplicate(pInfoItems[i].lpValue); #else strcpy(m_pArchiveInfo[i].Text, pInfoItems[i].lpName); strcpy(m_pArchiveInfo[i].Data, pInfoItems[i].lpValue); #endif } } ConstArray<PluginPanelItem> pPanelItems(100); Array<ArchiveTreeNode*> items; m_pArchive->SetCurrentDirectory(m_strPathInArchive, false); //а вдруг архив перезагрузили, вернем путь (с рута) m_pArchive->GetArchiveTreeItems(items, false); //no recursive for (unsigned int i = 0; i < items.count(); i++) { PluginPanelItem item; memset(&item, 0, sizeof(PluginPanelItem)); ArchiveTree* node = items.at(i); const ArchiveItem* src = node->GetOriginalItem(); item.FindData.lpwszFileName = StrDuplicate(node->GetFileName()); item.FindData.lpwszAlternateFileName = StrDuplicate(node->GetFileName()); item.UserData = (DWORD_PTR)node; if ( node->IsDummy() ) item.FindData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; else { item.FindData.dwFileAttributes = src->dwFileAttributes; item.FindData.nFileSize = src->nFileSize; item.FindData.nPackSize = src->nPackSize; memcpy(&item.FindData.ftCreationTime, &src->ftCreationTime, sizeof(FILETIME)); memcpy(&item.FindData.ftLastAccessTime, &src->ftLastAccessTime, sizeof(FILETIME)); memcpy(&item.FindData.ftLastWriteTime, &src->ftLastWriteTime, sizeof(FILETIME)); item.CRC32 = src->dwCRC32; } pPanelItems.add(item); } *pPanelItem = pPanelItems.data(); *pItemsNumber = pPanelItems.count(); return TRUE; }