bool Dictionary::is_valid_protection_domain(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data, Handle protection_domain) { DictionaryEntry* entry = get_entry(index, hash, name, loader_data); return entry->is_valid_protection_domain(protection_domain); }
void Dictionary::print() { ResourceMark rm; HandleMark hm; tty->print_cr("Java system dictionary (table_size=%d, classes=%d)", table_size(), number_of_entries()); tty->print_cr("^ indicates that initiating loader is different from " "defining loader"); for (int index = 0; index < table_size(); index++) { for (DictionaryEntry* probe = bucket(index); probe != NULL; probe = probe->next()) { if (Verbose) tty->print("%4d: ", index); Klass* e = probe->klass(); ClassLoaderData* loader_data = probe->loader_data(); bool is_defining_class = (loader_data == InstanceKlass::cast(e)->class_loader_data()); tty->print("%s%s", is_defining_class ? " " : "^", e->external_name()); tty->print(", loader "); loader_data->print_value(); tty->cr(); } } tty->cr(); _pd_cache_table->print(); tty->cr(); }
void Dictionary::verify() { guarantee(number_of_entries() >= 0, "Verify of system dictionary failed"); int element_count = 0; for (int index = 0; index < table_size(); index++) { for (DictionaryEntry* probe = bucket(index); probe != NULL; probe = probe->next()) { Klass* e = probe->klass(); ClassLoaderData* loader_data = probe->loader_data(); guarantee(e->oop_is_instance(), "Verify of system dictionary failed"); // class loader must be present; a null class loader is the // boostrap loader guarantee(loader_data != NULL || DumpSharedSpaces || loader_data->class_loader() == NULL || loader_data->class_loader()->is_instance(), "checking type of class_loader"); e->verify(); probe->verify_protection_domain_set(); element_count++; } } guarantee(number_of_entries() == element_count, "Verify of system dictionary failed"); debug_only(verify_lookup_length((double)number_of_entries() / table_size())); _pd_cache_table->verify(); }
Klass* Dictionary::find_shared_class(int index, unsigned int hash, Symbol* name) { assert (index == index_for(name, NULL), "incorrect index?"); DictionaryEntry* entry = get_entry(index, hash, name, NULL); return (entry != NULL) ? entry->klass() : (Klass*)NULL; }
DictionaryEntry* Dictionary::new_entry(unsigned int hash, Klass* klass, ClassLoaderData* loader_data) { DictionaryEntry* entry = (DictionaryEntry*)Hashtable<Klass*, mtClass>::new_entry(hash, klass); entry->set_loader_data(loader_data); entry->set_pd_set(NULL); assert(klass->oop_is_instance(), "Must be"); return entry; }
Klass* Dictionary::find_class(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data) { assert_locked_or_safepoint(SystemDictionary_lock); assert (index == index_for(name, loader_data), "incorrect index?"); DictionaryEntry* entry = get_entry(index, hash, name, loader_data); return (entry != NULL) ? entry->klass() : (Klass*)NULL; }
Klass* Dictionary::find(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { DictionaryEntry* entry = get_entry(index, hash, name, loader_data); if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) { return entry->klass(); } else { return NULL; } }
DictionaryEntry* Dictionary::new_entry(unsigned int hash, klassOop klass, oop loader) { DictionaryEntry* entry; entry=(DictionaryEntry*)Hashtable::new_entry(hash,POISON_KLASSREF(klassRef(klass))); entry->set_loader(ALWAYS_POISON_OBJECTREF(objectRef(loader))); entry->set_name(ALWAYS_POISON_OBJECTREF(objectRef(instanceKlass::cast(klass)->name()))); entry->set_pd_set(NULL); return entry; }
// All classes, and their class loaders // Don't iterate over placeholders void Dictionary::classes_do(void f(Klass*, ClassLoaderData*)) { for (int index = 0; index < table_size(); index++) { for (DictionaryEntry* probe = bucket(index); probe != NULL; probe = probe->next()) { Klass* k = probe->klass(); f(k, probe->loader_data()); } } }
void Dictionary::reorder_dictionary() { // Copy all the dictionary entries into a single master list. DictionaryEntry* master_list = NULL; for (int i = 0; i < table_size(); ++i) { DictionaryEntry* p = bucket(i); while (p != NULL) { DictionaryEntry* tmp; tmp = p->next(); p->set_next(master_list); master_list = p; p = tmp; } set_entry(i, NULL); } // Add the dictionary entries back to the list in the correct buckets. while (master_list != NULL) { DictionaryEntry* p = master_list; master_list = master_list->next(); p->set_next(NULL); Symbol* class_name = InstanceKlass::cast((Klass*)(p->klass()))->name(); // Since the null class loader data isn't copied to the CDS archive, // compute the hash with NULL for loader data. unsigned int hash = compute_hash(class_name, NULL); int index = hash_to_index(hash); p->set_hash(hash); p->set_loader_data(NULL); // loader_data isn't copied to CDS p->set_next(bucket(index)); set_entry(index, p); } }
// Added for initialize_itable_for_klass to handle exceptions // Just the classes from defining class loaders void Dictionary::classes_do(void f(Klass*, TRAPS), TRAPS) { for (int index = 0; index < table_size(); index++) { for (DictionaryEntry* probe = bucket(index); probe != NULL; probe = probe->next()) { Klass* k = probe->klass(); if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) { f(k, CHECK); } } } }
void Dictionary::methods_do(void f(Method*)) { for (int index = 0; index < table_size(); index++) { for (DictionaryEntry* probe = bucket(index); probe != NULL; probe = probe->next()) { Klass* k = probe->klass(); if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) { // only take klass is we have the entry with the defining class loader InstanceKlass::cast(k)->methods_do(f); } } } }
// This routine does not lock the system dictionary. // // Since readers don't hold a lock, we must make sure that system // dictionary entries are only removed at a safepoint (when only one // thread is running), and are added to in a safe way (all links must // be updated in an MT-safe manner). // // Callers should be aware that an entry could be added just after // _buckets[index] is read here, so the caller will not see the new entry. DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash, Symbol* class_name, ClassLoaderData* loader_data) { debug_only(_lookup_count++); for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) { if (entry->hash() == hash && entry->equals(class_name, loader_data)) { return entry; } debug_only(_lookup_length++); } return NULL; }
void Dictionary::always_strong_classes_do(KlassClosure* closure) { // Follow all system classes and temporary placeholders in dictionary for (int index = 0; index < table_size(); index++) { for (DictionaryEntry* probe = bucket(index); probe != NULL; probe = probe->next()) { Klass* e = probe->klass(); ClassLoaderData* loader_data = probe->loader_data(); if (is_strongly_reachable(loader_data, e)) { closure->do_klass(e); } } } }
void EnchantSpellingAlternativesPrivate::setEnchantSpellingAlternatives( Token* token, MorphoSyntacticData* tokenData, FsaStringsPool& sp) { // try to find simple Uncapitalization MORPHOLOGINIT; // FIXME Conditions below could be process unit parameters const LimaString& tokenStr=token->stringForm(); if (token->status().getAlphaCapital() == T_CAPITAL || token->status().getAlphaCapital() == T_CAPITAL_1ST || token->status().getAlphaCapital() == T_CAPITAL_SMALL || token->status().isAlphaConcatAbbrev() || token->status().isAlphaHyphen() || token->status().isAlphaPossessive() || tokenStr.toUpper() == tokenStr) { return; } std::vector<std::string> suggestions = m_enchantDictionary->suggest(tokenStr.toUtf8().constData()); for (std::vector<std::string>::const_iterator it = suggestions.begin(); it != suggestions.end();it++) { LimaString correction = LimaString::fromUtf8((*it).c_str()); // FIXME Conditions below could be process unit parameters if ( correction.size() > 1 && correction != tokenStr ) { DictionaryEntry* entry = new DictionaryEntry(m_dictionary->getEntry(correction)); MorphoSyntacticDataHandler lingInfosHandler(*tokenData, SPELLING_ALTERNATIVE); if (!entry->isEmpty()) { LINFO << "EnchantSpellingAlternativesPrivate::setEnchantSpellingAlternatives correcting" << tokenStr << "into" << correction; // add orthographic alternative to Token; StringsPoolIndex idx=sp[correction]; token->addOrthographicAlternatives(idx); if (entry->hasLingInfos()) { entry->parseLingInfos(&lingInfosHandler); } } else { delete entry; } } } }
void Dictionary::add_protection_domain(int index, unsigned int hash, instanceKlassHandle klass, ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { Symbol* klass_name = klass->name(); DictionaryEntry* entry = get_entry(index, hash, klass_name, loader_data); assert(entry != NULL,"entry must be present, we just created it"); assert(protection_domain() != NULL, "real protection domain should be present"); entry->add_protection_domain(this, protection_domain()); assert(entry->contains_protection_domain(protection_domain()), "now protection domain should be present"); }
void Dictionary::always_strong_oops_do(OopClosure* blk) { // Follow all system classes and temporary placeholders in dictionary; only // protection domain oops contain references into the heap. In a first // pass over the system dictionary determine which need to be treated as // strongly reachable and mark them as such. for (int index = 0; index < table_size(); index++) { for (DictionaryEntry *probe = bucket(index); probe != NULL; probe = probe->next()) { Klass* e = probe->klass(); ClassLoaderData* loader_data = probe->loader_data(); if (is_strongly_reachable(loader_data, e)) { probe->set_strongly_reachable(); } } } // Then iterate over the protection domain cache to apply the closure on the // previously marked ones. _pd_cache_table->always_strong_oops_do(blk); }
void OrthographicAlternatives::createAlternative( Token* srcToken, MorphoSyntacticData* tokenData, LimaString& str, AnalysisDict::AbstractAnalysisDictionary* dictionary, StringsPool& sp) { MORPHOLOGINIT; LDEBUG << "OrthographicAlternatives::createAlternative" << str; DictionaryEntry* dicoEntry = new DictionaryEntry(dictionary->getEntry(str)); if (!dicoEntry->isEmpty()) { // add orthographic alternative to Token; StringsPoolIndex infl=sp[str]; Token* altToken=new Token(infl,str,srcToken->position(),srcToken->length(),new TStatus(*(srcToken->status()))); altToken->setDictionaryEntry(dicoEntry); srcToken->addOrthographicAlternative(altToken); tokenData->appendLingInfo(infl,dicoEntry,ORTHOGRAPHIC_ALTERNATIVE,sp); // if entry has other accented forms, // keep them ("PARIS" -> "paris" -> "Paris") if (dicoEntry->hasAccented()) { dicoEntry->reset(); Lima::LimaString alternativeStr = dicoEntry->nextAccented(); while (alternativeStr.size() != 0) { // give it its simple word entry into dictionary DictionaryEntry* altDicoEntry = new DictionaryEntry(dictionary->getEntry(alternativeStr)); StringsPoolIndex infl2=sp[alternativeStr]; tokenData->appendLingInfo(infl2,altDicoEntry,ORTHOGRAPHIC_ALTERNATIVE,sp); // add orthographic alternative to Token Token* altToken2=new Token(infl2,alternativeStr,srcToken->position(),srcToken->length(),new TStatus(*(srcToken->status()))); altToken2->setDictionaryEntry(altDicoEntry); srcToken->addOrthographicAlternative(altToken2); alternativeStr = dicoEntry->nextAccented(); } } } else { delete dicoEntry; } }
const thomsonreuters::ema::access::EmaString& DataDictionaryImpl::toString() const { if (!_pRsslDataDictionary->isInitialized) { _stringToString.clear().append("DataDictionary is not initialized"); return _stringToString; } _stringToString.set(0, 2000000); _stringToString.append("Data Dictionary Dump: MinFid=").append(getMinFid()).append(" MaxFid=").append(getMaxFid()). append(" NumEntries ").append(_pRsslDataDictionary->numberOfEntries).append("\n\n"); _stringToString.append("Tags:\n DictionaryId=\"").append(getInfoDictionaryId()).append("\"\n\n"); _stringToString.append(" [Field Dictionary Tags]\n"). append(" Filename=\"").append(getFieldFilename()).append("\"\n"). append(" Desc=\"").append(getFieldDescription()).append("\"\n"). append(" Version=\"").append(getFieldVersion()).append("\"\n"). append(" Build=\"").append(getFieldBuild()).append("\"\n"). append(" Date=\"").append(getFieldDate()).append("\"\n\n"); _stringToString.append(" [Enum Type Dictionary Tags]\n"). append(" Filename=\"").append(getEnumFilename()).append("\"\n"). append(" Desc=\"").append(getEnumDescription()).append("\"\n"). append(" RT_Version=\"").append(getEnumRecordTemplateVersion()).append("\"\n"). append(" DT_Version=\"").append(getEnumDisplayTemplateVersion()).append("\"\n"). append(" Date=\"").append(getEnumDate()).append("\"\n\n"); _stringToString.append("Field Dictionary:\n"); RsslDictionaryEntry* rsslDictionaryEntry = 0; DictionaryEntry dictionaryEntry; for (Int32 index = 0; index <= _pRsslDataDictionary->maxFid; index++) { rsslDictionaryEntry = *(_pRsslDataDictionary->entriesArray + index); if (rsslDictionaryEntry) { dictionaryEntry._pImpl->rsslDictionaryEntry(rsslDictionaryEntry); _stringToString.append(" Fid=").append(dictionaryEntry.getFid()).append(" '").append(dictionaryEntry.getAcronym()). append("' '").append(dictionaryEntry.getDDEAcronym()). append("' Type=").append(dictionaryEntry.getFieldType()). append(" RippleTo=").append(dictionaryEntry.getRippleToField()).append(" Len=").append(dictionaryEntry.getLength()). append(" EnumLen=").append(dictionaryEntry.getEnumLength()). append(" RwfType=").append(dictionaryEntry.getRwfType()).append(" RwfLen=").append(dictionaryEntry.getRwfLength()).append("\n"); } } _stringToString.append("\nEnum Type Tables:\n"); RsslEnumTypeTable* rsslEnumTypeTable = 0; EnumTypeTable enumTypeTable; for (UInt16 index = 0; index <= _pRsslDataDictionary->enumTableCount; index++) { rsslEnumTypeTable = *(_pRsslDataDictionary->enumTables + index); if ( rsslEnumTypeTable ) { enumTypeTable._pImpl->rsslEnumTypeTable( rsslEnumTypeTable ); _stringToString.append(enumTypeTable.toString()); _stringToString.append("\n"); } } return _stringToString; }
bool Dictionary::do_unloading() { assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); bool class_was_unloaded = false; int index = 0; // Defined here for portability! Do not move // Remove unloadable entries and classes from system dictionary // The placeholder array has been handled in always_strong_oops_do. DictionaryEntry* probe = NULL; for (index = 0; index < table_size(); index++) { for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) { probe = *p; Klass* e = probe->klass(); ClassLoaderData* loader_data = probe->loader_data(); InstanceKlass* ik = InstanceKlass::cast(e); // Non-unloadable classes were handled in always_strong_oops_do if (!is_strongly_reachable(loader_data, e)) { // Entry was not visited in phase1 (negated test from phase1) assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader"); ClassLoaderData* k_def_class_loader_data = ik->class_loader_data(); // Do we need to delete this system dictionary entry? bool purge_entry = false; // Do we need to delete this system dictionary entry? if (loader_data->is_unloading()) { // If the loader is not live this entry should always be // removed (will never be looked up again). Note that this is // not the same as unloading the referred class. if (k_def_class_loader_data == loader_data) { // This is the defining entry, so the referred class is about // to be unloaded. class_was_unloaded = true; } // Also remove this system dictionary entry. purge_entry = true; } else { // The loader in this entry is alive. If the klass is dead, // (determined by checking the defining class loader) // the loader must be an initiating loader (rather than the // defining loader). Remove this entry. if (k_def_class_loader_data->is_unloading()) { // If we get here, the class_loader_data must not be the defining // loader, it must be an initiating one. assert(k_def_class_loader_data != loader_data, "cannot have live defining loader and unreachable klass"); // Loader is live, but class and its defining loader are dead. // Remove the entry. The class is going away. purge_entry = true; } } if (purge_entry) { *p = probe->next(); if (probe == _current_class_entry) { _current_class_entry = NULL; } free_entry(probe); continue; } } p = probe->next_addr(); } } return class_was_unloaded; }
QDomElement DictionaryEntryWriter::write(const DictionaryEntry &entry) { QDomElement entryNode = nodeCreator->createNode(DictionaryEntryAttributes::ENTRY_TAG); entryNode.appendChild(nodeCreator->createSimpleTextNode(DictionaryEntryAttributes::NAME_ATTRIBUTE, entry.name())); entryNode.appendChild(nodeCreator->createSimpleTextNode(DictionaryEntryAttributes::TYPE_ATTRIBUTE, entry.type())); entryNode.appendChild(nodeCreator->createSimpleTextNode(DictionaryEntryAttributes::SIGNIFICATION_ATTRIBUTE, entry.signification())); return entryNode; }
int main (int argc, char *argv[]){ HashTable<DictionaryEntry> hashtb = HashTable<DictionaryEntry>() ; if (argc != 2){ //if there is an incorrect number of arguments, which means the arguments have to equal 2 cout << "Incorrect Number of Command Line Arguments" << endl; exit(1);//exit program } std::string filetoopen; filetoopen = argv[1]; std::ifstream frenchfile(filetoopen.c_str()); // This uses the ifstream class to open and read the text file line by line string currentline; vector<string> input;//this has duplicates std::string str2 ("#"); int vectornum=0; string needed; string word; string definition; if (frenchfile.is_open()){ //as long as the ifstream is open while(getline(frenchfile, currentline)){ //std::size_t found = currentline.find(str2); //if (found!=std::string::npos){ //} //else{ stringstream currentlinestream(currentline); needed = currentline; getline(currentlinestream, needed, '\t'); word=needed; getline(currentlinestream, needed, '\t'); definition = needed; input.push_back(word); input.push_back(definition); vectornum=vectornum+2; //} } frenchfile.close(); //close the fstream, save memory. } else { cout << "Can't open the file. Wrong filename or doesn't exist." << endl; exit(1); } int numberofwords = 0; vector<string> noduplicate; for(int i = 0; i < vectornum;i+=2){ DictionaryEntry temp(input[i],input[i+1]); if(hashtb.insert(temp)==true){ hashtb.insert(temp); noduplicate.push_back(input[i]); numberofwords++; } } string userenter; int random=0; srand(time(NULL)); /* seed random number generator */ while (1<2){ cin >> userenter; if (userenter == "random"){ random = rand()%numberofwords; DictionaryEntry output = hashtb.retrieve(noduplicate[random]); cout << output.getword()<< endl; cout << output.getdefinition() << endl; } else{ DictionaryEntry gotten; gotten = hashtb.retrieve(userenter); cout << gotten.getword()<< endl; cout << gotten.getdefinition() << endl; } } }