int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize orb CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); if (parse_args (argc, argv) != 0) return 1; //Get reference to Root POA CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); // Activate POA Manager PortableServer::POAManager_var mgr = poa->the_POAManager(); mgr->activate(); // Find the Naming Service obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root = CosNaming::NamingContextExt::_narrow(obj.in()); if (CORBA::is_nil(root.in())) { std::cerr << "Nil Naming Context reference" << std::endl; return 1; } // Bind a new context. CosNaming::Name name; name.length( 1 ); name[0].id = CORBA::string_dup( "root.esc-dot" ); name[0].kind = CORBA::string_dup( "kind1" ); try { obj = root->resolve(name); } catch(const CosNaming::NamingContext::NotFound&) { CosNaming::NamingContext_var dummy = root->bind_new_context(name); } name.length( 2 ); name[1].id = CORBA::string_dup( "leaf/esc-slash" ); name[1].kind = CORBA::string_dup( "kind2" ); // Create an object PortableServer::Servant_var<Messenger_i> servant = new Messenger_i; PortableServer::ObjectId_var oid = poa->activate_object(servant.in()); CORBA::Object_var messenger_obj = poa->id_to_reference(oid.in()); root->rebind(name, messenger_obj.in()); // Also try rebinding to a simple path. CosNaming::Name_var simp_name = root->to_name("Simple"); try { obj = root->resolve(simp_name.in()); } catch(const CosNaming::NamingContext::NotFound&) { CosNaming::NamingContext_var dummy = root->bind_new_context(simp_name.in()); } simp_name = root->to_name("Simple/Messenger"); root->rebind(simp_name.in(), messenger_obj.in()); // Convert Name to String Name. CORBA::String_var str_name = root->to_string(name); std::cout << "str_name: " << str_name.in() << std::endl; CORBA::String_var str_simple = root->to_string(simp_name.in()); std::cout << "simple: " << str_simple.in() << std::endl; // Convert String Name to Name. CosNaming::Name_var tname = root->to_name(str_name.in()); std::cout << "converted back to a CosNaming::Name: " << std::endl; std::cout << " name[0] = " << (* tname)[0].id.in() << " , " << (* tname)[0].kind.in() << std::endl; std::cout << " name[1] = " << (* tname)[1].id.in() << " , " << (* tname)[1].kind.in() << std::endl; // Find the application object by resolve_str. try { obj = root->resolve_str(str_name.in()); } catch(const CosNaming::NamingContext::NotFound&) { std::cerr<<"Couldn't resolve the string name: " << str_name << std::endl; return 1; } ACE_CString base_address (":"); base_address += ACE_TEXT_ALWAYS_CHAR (hostname); base_address += ":"; base_address += ACE_TEXT_ALWAYS_CHAR (port); ACE_CString addr (""); addr = base_address + "/key/str"; // Create an URL string for application object. CORBA::String_var address = CORBA::string_dup (addr.c_str()); std::cout << "call to_url(\"" << address.in() << "\"" << std::endl; std::cout << " ,\"" << str_simple.in() << "\")"<< std::endl; CORBA::String_var url_string = root->to_url(address.in(), str_simple.in()); std::cout << "to_url result: " << url_string.in() << std::endl; // Write NS url to a file to let client read NS URL to get // NamingContext reference. CORBA::String_var ns_addr = CORBA::string_dup(base_address.c_str()); std::cout << "call to_url(\"" <<ns_addr.in() << "\",\"" << str_simple.in() << "\")"<< std::endl; CORBA::String_var url = root->to_url(ns_addr.in(), str_simple.in()); std::cout << "to_url result: " << url.in() << std::endl; std::ofstream iorFile(ACE_TEXT_ALWAYS_CHAR (ior_output_file)); iorFile << url.in() << std::endl; iorFile.close(); std::cout << "Naming Service URL written to file " << ior_output_file << std::endl; // Accept requests orb->run(); orb->destroy(); } catch(const CORBA::Exception& ex) { std::cerr << "Caught a CORBA::Exception: " << ex << std::endl; return 1; } return 0; }
ReturnOop SymbolTable::symbol_for(TypeArray *byte_array, utf8 s, int len, bool check_only JVM_TRAPS) { if (byte_array == NULL) { // If the source of the new symbol lives in the heap, you must // GC-protect it by passing the source in a byte_array GUARANTEE(!ObjectHeap::contains((OopDesc*)s), "must not be in heap"); } if (unsigned(len) > 0xfff0) { // Symbol's string length is a unsigned 16-bit number Throw::out_of_memory_error(JVM_SINGLE_ARG_THROW_0); } const juint hash_value = hash(s, len); if (UseROM) { // The ROM symbol table's layout is different than that of the // symbol table in heap. The main reason is to avoids holes in // the table. // // ************************************************************** // WARNING: the value of ROM::symbol_table_num_buckets() is 1 off // what you would think. Read the following carefully. // ************************************************************** // // Layout of the ROM symbol table with <n> buckets: // // (a) The first <n> elements are pointers to the start of the // <n> buckets. Note that element <n> also marks the exclusive // end of the <n-1> bucket. // (b) One additional element is written at to mark the exclusive // end of the very last bucket. // (c) If RewriteROMConstantPool is disabled, the contents of // bucket #0 starts here, followed by the contents of bucket #1, // and so forth. // // For example, say we have two buckets; bucket #0 contains "foo"; // bucket #1 contains "bar" and "blah": // // symbol_table_size = 2; // symbol_table[] = { // &symbol_table[3]; // (a) start of bucket#0 // &symbol_table[4]; // (a) end of bucket#0/start of bucket#1 // &symbol_table[6]; // (b) end of bucket#1 // pointer to Symbol "foo"; // (c) item in bucket#0 // pointer to Symbol "bar"; // (c) item in bucket#1 // pointer to Symbol "blah"; // (c) item in bucket#1 // }; // // Note that if RewriteROMConstantPool is enabled (the default), // part (c) is actually stored inside the merged constant pool; // parts (a) and (b) are written with special macros to point to // the merged constant pool instead. ReturnOop old_sym = ROM::symbol_for(s, hash_value, len); if( old_sym ) { return old_sym; } } const juint mask = juint(length() - 1); juint index = hash_value & mask; const juint start = index; SymbolDesc**base = (SymbolDesc**)base_address(); SymbolDesc* old; if (0 < len && len <= 6) { // Quicker search. This happens very frequently if a MIDlet is // obfuscated -- many variables will have name length <= 6 // // Note: this requires that the unused space in the SymbolDesc be filled // with zeros. union { jushort shorts[4]; juint ints[2]; } blob; blob.ints[0] = 0; blob.ints[1] = 0; blob.shorts[0] = (jushort)len; jvm_memcpy(&blob.shorts[1], s, len); const juint blob0 = blob.ints[0]; if( len <= 2 ) { do { old = base[index]; if( old == NULL ) break; const juint *body = ((const juint*)old) + sizeof(OopDesc)/BytesPerWord; if (blob0 == body[0]) { return (ReturnOop)old; } index ++; index &= mask; // Do not rewrite as while( (index = (++index & mask)) != start ); // ADS compiler generates incorrect code. } while( index != start ); } else { const juint blob1 = blob.ints[1]; do { old = base[index]; if( old == NULL ) break; const juint *body = ((const juint*)old) + sizeof(OopDesc)/BytesPerWord; if( blob0 == body[0] && blob1 == body[1] ) { return (ReturnOop)old; } index ++; index &= mask; // Do not rewrite as while( (index = (++index & mask)) != start ); // ADS compiler generates incorrect code. } while( index != start ); } } else { do { old = base[index]; if( old == NULL ) break; if( old->matches(s, len)) { return (ReturnOop)old; } index ++; index &= mask; // Do not rewrite as while( (index = (++index & mask)) != start ); // ADS compiler generates incorrect code. } while( index != start ); } if (check_only) { // The specified symbol is not found return NULL; } else { if( old ) { // We'd come to here if we're really out of memory Throw::out_of_memory_error(JVM_SINGLE_ARG_THROW_0); } // Create a new Symbol of the specified value UsingFastOops fast_oops; Symbol::Fast new_symbol = Universe::new_symbol(byte_array, s, len JVM_CHECK_0); obj_at_put(index, &new_symbol); int new_count = Task::current()->incr_symbol_table_count(); if (new_count > desired_max_symbol_count()) { grow_and_replace_symbol_table(); } return new_symbol.obj(); } }
jchar *char_base_address() { GUARANTEE(ObjectHeap::is_gc_active() || is_char_array(), "type check"); return (jchar*)base_address(); }
juint *uint_base_address() { GUARANTEE(ObjectHeap::is_gc_active() || is_int_array(), "type check"); return (juint*)base_address(); }
jubyte *ubyte_base_address() { GUARANTEE(ObjectHeap::is_gc_active() || is_byte_array(), "type check"); return (jubyte*)base_address(); }