int MethodHandles::method_handle_entry_linkToVirtual(Method* method, intptr_t UNUSED, TRAPS) { JavaThread *thread = (JavaThread *) THREAD; InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); interpreterState istate = frame->interpreter_state(); // Pop appendix argument from stack. This is a MemberName which we resolve to the // target method. oop vmentry = popFromStack(THREAD); intptr_t* topOfStack = istate->stack(); // Resolve target method by looking up in the receiver object's vtable. intptr_t vmindex = java_lang_invoke_MemberName::vmindex(vmentry); Method* target = (Method*) java_lang_invoke_MemberName::vmtarget(vmentry); int numArgs = target->size_of_parameters(); oop recv = STACK_OBJECT(-numArgs); Klass* clazz = recv->klass(); Klass* klass_part = InstanceKlass::cast(clazz); klassVtable* vtable = klass_part->vtable(); Method* vmtarget = vtable->method_at(vmindex); invoke_target(vmtarget, THREAD); return 0; }
int MethodHandles::method_handle_entry_linkToInterface(Method* method, intptr_t UNUSED, TRAPS) { JavaThread *thread = (JavaThread *) THREAD; InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); interpreterState istate = frame->interpreter_state(); // Pop appendix argument from stack. This is a MemberName which we resolve to the // target method. oop vmentry = popFromStack(THREAD); intptr_t* topOfStack = istate->stack(); // Resolve target method by looking up in the receiver object's itable. Klass* clazz = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(vmentry)); intptr_t vmindex = java_lang_invoke_MemberName::vmindex(vmentry); Method* target = (Method*) java_lang_invoke_MemberName::vmtarget(vmentry); int numArgs = target->size_of_parameters(); oop recv = STACK_OBJECT(-numArgs); InstanceKlass* klass_part = InstanceKlass::cast(recv->klass()); itableOffsetEntry* ki = (itableOffsetEntry*) klass_part->start_of_itable(); int i; for ( i = 0 ; i < klass_part->itable_length() ; i++, ki++ ) { if (ki->interface_klass() == clazz) break; } itableMethodEntry* im = ki->first_method_entry(recv->klass()); Method* vmtarget = im[vmindex].method(); invoke_target(vmtarget, THREAD); return 0; }
bool FilterHandler::handle(HttpRequest* req, HttpResponse* res, const string& ext, Reflector& reflector) { string acurl = req->getActUrl(); RegexUtil::replace(acurl,"[/]+","/"); if(acurl.find("/"+req->getCntxt_name())!=0) acurl = "/" + req->getCntxt_name() + "/" + acurl; RegexUtil::replace(acurl,"[/]+","/"); bool continue_proc_request = true; Logger logger = LoggerFactory::getLogger("FilterHandler"); vector<string> filters; if(getFilterForPath(req->getCntxt_name(), acurl, filters, "handle")) { for (int var = 0; var < (int)filters.size(); ++var) { string claz = filters.at(var); void *_temp = ConfigurationData::getInstance()->ffeadContext.getBean("filter_"+claz, req->getCntxt_name()); args argus; argus.push_back("HttpRequest*"); argus.push_back("HttpResponse*"); vals valus; const ClassInfo& srv = ConfigurationData::getInstance()->ffeadContext.classInfoMap[req->getCntxt_name()][claz]; Method meth = srv.getMethod("doHandle", argus); if(meth.getMethodName()!="") { valus.push_back(req); valus.push_back(res); continue_proc_request = reflector.invokeMethod<bool>(_temp,meth,valus); logger << "Handler Filter called" << endl; } ConfigurationData::getInstance()->ffeadContext.release("filter_"+claz, req->getCntxt_name()); } } return continue_proc_request; }
ISequence<MethodSignature>* MethodsList::extractAndSyncAnyExtraMethods( Method& method ) { ISequence<MethodSignature>* method_signatures = new Sequence<MethodSignature>(); { ISequence<Method>* extra_methods = method.extractExtraMethods(); if ( extra_methods ) { ClassSignature class_signature( this->cu.getFQName() ); while ( ! extra_methods->isEmpty() ) { Method* method = extra_methods->removeLast(); if ( method->sync() ) { const char* method_key = method->getSignature().getMethodKey().getChars(); this->methods->insert( method_key, method ); method_signatures->addLast( new MethodSignature( class_signature, method_key ) ); } else { delete method_signatures; method_signatures = NULL; break; } } } delete extra_methods; } return method_signatures; }
static void sort_methods(GrowableArray<Method*>* methods) { // Note that this must sort using the same key as is used for sorting // methods in InstanceKlass. bool sorted = true; for (int i = methods->length() - 1; i > 0; --i) { for (int j = 0; j < i; ++j) { Method* m1 = methods->at(j); Method* m2 = methods->at(j + 1); if ((uintptr_t)m1->name() > (uintptr_t)m2->name()) { methods->at_put(j, m2); methods->at_put(j + 1, m1); sorted = false; } } if (sorted) break; sorted = true; } #ifdef ASSERT uintptr_t prev = 0; for (int i = 0; i < methods->length(); ++i) { Method* mh = methods->at(i); uintptr_t nv = (uintptr_t)mh->name(); assert(nv >= prev, "Incorrect overpass method ordering"); prev = nv; } #endif }
static Method* new_method( BytecodeConstantPool* cp, BytecodeBuffer* bytecodes, Symbol* name, Symbol* sig, AccessFlags flags, int max_stack, int params, ConstMethod::MethodType mt, TRAPS) { address code_start = 0; int code_length = 0; InlineTableSizes sizes; if (bytecodes != NULL && bytecodes->length() > 0) { code_start = static_cast<address>(bytecodes->adr_at(0)); code_length = bytecodes->length(); } Method* m = Method::allocate(cp->pool_holder()->class_loader_data(), code_length, flags, &sizes, mt, CHECK_NULL); m->set_constants(NULL); // This will get filled in later m->set_name_index(cp->utf8(name)); m->set_signature_index(cp->utf8(sig)); #ifdef CC_INTERP ResultTypeFinder rtf(sig); m->set_result_index(rtf.type()); #endif m->set_size_of_parameters(params); m->set_max_stack(max_stack); m->set_max_locals(params); m->constMethod()->set_stackmap_data(NULL); m->set_code(code_start); return m; }
void InterpretTest::gcTest() { ConstantPool * pool = new ConstantPool(); Class * cls = initClass("GCTest", pool); const char code[] = { PUSH, 0x00, 0x00, STORE_LOCAL, 0x00, PUSH, 0x01, 0x00, //label1 LOAD_LOCAL, 0x00, SUB, IF_GE, 0x0D,//if(i < 1000) PUSH, 0x01, 0x00, NEW_ARRAY, STORE_LOCAL, 0x01, LOAD_LOCAL, 0x00, INC, STORE_LOCAL, 0x00, JMP, -21, RET_VOID }; Method * m = initMethod("gcTest", code, sizeof(code), 0, 2, 0); ClassLoader cl(""); Interpret instance(&cl); IntConst i; i.value = 0; pool->addItem(&i, INT_CONST);//0 i.value = 1000; pool->addItem(&i, INT_CONST);//1 cls->addMethod(m); cl.addClass(cls); instance.run(cls->getName().c_str(), m->getName().c_str()); }
void ServiceTask::handleWebsockClose(WebSocketData* req) { Reflector reflector(ConfigurationData::getInstance()->dlib); std::string className; std::map<std::string, std::map<std::string, std::string> >& websocketMappingMap = ConfigurationData::getInstance()->websocketMappingMap; std::map<std::string, std::string> websockcntMap = websocketMappingMap[req->getCntxt_name()]; std::map<std::string, std::string>::iterator it; for (it=websockcntMap.begin();it!=websockcntMap.end();++it) { if(ConfigurationData::urlMatchesPath(req->getCntxt_name(), it->first, req->getUrl())) { className = it->second; break; } } if(className!="") { void *_temp = ConfigurationData::getInstance()->ffeadContext.getBean("websocketclass_"+className, req->getCntxt_name()); args argus; vals valus; const ClassInfo& srv = ConfigurationData::getClassInfo(className, req->getCntxt_name()); Method methc = srv.getMethod("onClose", argus); if(methc.getMethodName()!="") { //logger << ("WebSocket Controller " + className + " called") << std::endl; reflector.invokeMethodGVP(_temp,methc,valus); logger << "WebSocket Controller onClose" << std::endl; } else { logger << "Invalid WebSocket Controller" << std::endl; } } }
void InterpretTest::aritmeticTest() { ConstantPool * pool = new ConstantPool(); Class * cls = initClass("AritmeticTest", pool); const char code[] = { PUSH, 0x00, 0x00, PUSH, 0x01, 0x00, ADD, PUSH, 0x00, 0x00, SUB, PUSH, 0x00, 0x00, MUL, PUSH, 0x00, 0x00, DIV, INC, DEC, RET }; Method * m = initMethod("aritmeticTest", code, sizeof(code), 0, 0, 0); ClassLoader cl(""); Interpret instance(&cl); IntConst i; i.value = 20; pool->addItem(&i, INT_CONST); i.value = 30; pool->addItem(&i, INT_CONST); cls->addMethod(m); cl.addClass(cls); assert(30 == instance.run(cls->getName().c_str(), m->getName().c_str())); }
void InterpretTest::localsTest() { ConstantPool * pool = new ConstantPool(); Class * cls = initClass("LocalsTest", pool); const char code[] = { PUSH, 0x00, 0x00, STORE_LOCAL, 0x00, PUSH, 0x01, 0x00, STORE_LOCAL, 0x01, LOAD_LOCAL, 0x00, LOAD_LOCAL, 0x01, ADD, RET }; Method * m = initMethod("localsTest", code, sizeof(code), 0, 2, 0); ClassLoader cl(""); Interpret instance(&cl); IntConst i; i.value = 20; pool->addItem(&i, INT_CONST); i.value = 30; pool->addItem(&i, INT_CONST); cls->addMethod(m); cl.addClass(cls); assert(50 == instance.run(cls->getName().c_str(), m->getName().c_str())); }
// check all the function to find precedures void MarkProcedure() { //check all the function if it calls wait for semwait mark it and mark all its parents as candidate for(map<string, Method*>::iterator iter = methods.begin(); iter != methods.end(); iter++) { Method *m = iter->second; if (m->candidate) continue; for (set<string>::iterator call_iter = m->callexprs.begin(); call_iter != m->callexprs.end(); call_iter++) { string callee = *call_iter; if (isWaitFunctionCall(callee) || isSemWaitCall(callee)) { MakeAsCandidate(m); break; } } } for(map<string, Method*>::iterator iter = methods.begin(); iter != methods.end(); iter++) { iter->second->visit = false; iter->second->isProcedure = false; } //start from starting procedure traverse the call chain for(map<string, Method*>::iterator iter = methods.begin(); iter != methods.end(); iter++) { Method *m = iter->second; if (m->isStartingProcedure(records)) { TraverseProcedure(m); } } }
void BackEnd::resolve(FuncDeclaration& decl) { assert(!decl.csym); ModuleEmitter& modScope = getModuleScope(decl.loc); // is the function declared in the scope of the current module? if (decl.scope && decl.scope->module == &modScope.getModule()) { if (ClassDeclaration* classDecl = decl.isClassMember()) { Class& c = static_cast<Class&>(DEREF(classDecl->csym)); modScope.createMethod(c.getBlock(), decl); } else { modScope.createFunction(decl); } } else { // create a method at the assembly level (where it does not get emitted) Method* method = new Method(decl, 0); getAssembly().add(*method); decl.csym = method; if (decl.ident == Id::eq) { //force dispatch thru the System.Object's vtable method->setProto(L"bool object::Equals(object)", 1); } } }
static TclObject methodToListObj (const Method &method) { TclObject list(Tcl_NewListObj(0, 0)); // Put member id. list.lappend(Tcl_NewIntObj(method.memberid())); // Put return type. list.lappend(typeToListObj(method.type())); // Put method name. list.lappend( Tcl_NewStringObj(const_cast<char *>(method.name().c_str()), -1)); // Put parameters. TclObject parameterList(Tcl_NewListObj(0, 0)); const Method::Parameters ¶meters = method.parameters(); for (Method::Parameters::const_iterator p = parameters.begin(); p != parameters.end(); ++p) { parameterList.lappend(parameterToListObj(*p)); } list.lappend(parameterList); return list; }
QStandardItemModel * LookupDialog::modelForMethod(const QString & methodName) { const Introspection & introspection = Main::scProcess()->introspection(); const MethodMap & methods = introspection.methodMap(); pair<MethodMap::const_iterator, MethodMap::const_iterator> matchingMethods = methods.equal_range(methodName); if (matchingMethods.first == matchingMethods.second) return NULL; QStandardItemModel * model = new QStandardItemModel(this); QStandardItem *parentItem = model->invisibleRootItem(); for (MethodMap::const_iterator it = matchingMethods.first; it != matchingMethods.second; ++it) { Method *method = it->second.data(); QString signature = method->signature( Method::SignatureWithoutArguments ); const QString & path = method->definition.path; QString displayPath = introspection.compactLibraryPath(path); parentItem->appendRow(makeDialogItem( signature, displayPath, method->definition.path.get(), method->definition.position, method->ownerClass->name.get(), method->name.get(), false )); } model->sort(0); return model; }
void GenerateServerMethods::generate_CPP_USER(const std::string &destdir, const std::string &name) { const std::string h_name = theClass.getBaseName() + "_ulxr_server.h"; std::string cpp_name = destdir + theClass.getBaseName() + "_ulxr_server_user.cpp"; struct stat statbuf; if (stat(cpp_name.c_str(), &statbuf) >= 0) { std::cout << "User file already exists: " << cpp_name << std::endl; cpp_name += ".new"; std::cout << "New template will be created: " << cpp_name << std::endl; } std::ofstream cpp_file(cpp_name.c_str()); std::cout << "User file will be created: " << cpp_name << std::endl; generateUserSourceHead(cpp_file, h_name); cpp_file << "#include <ulxmlrpcpp/ulxr_response.h>\n"; cpp_file << "#include <ulxmlrpcpp/ulxr_method_adder.h>\n"; cpp_file << "#include <ulxmlrpcpp/ulxr_signature.h>\n\n"; cpp_file << "#include \"" << theClass.getSource() << "\"\n"; cpp_file << "#include \"" << name + "_ulxr_names.h" << "\"\n\n"; cpp_file << "\nvoid " << name << "Server::setupServerMethods()\n" "{\n"; for (unsigned i = 0; i < theClass.numMethods(); ++i) { if (i != 0) cpp_file << "\n"; Method method = theClass.getMethod(i); method.extractNamespace(); cpp_file << " // mapped to: " << method.getCppString(0, false, ""); if (method.getName() != method.getOverloadName()) cpp_file << " (there are overloaded methods)"; cpp_file << "\n" " method_adder.addMethod(ulxr::make_method(*this, &" << method.getOverloadName(true, "Server") << "),\n" " " << method.getType().getRpcName() << "::getValueName(),\n" " ULXR_CALLTO_" << method.getOverloadName(true, "", "_") << ",\n" " ulxr::Signature()"; for (unsigned p = 0; p < method.numArgs(); ++p) cpp_file << "\n << " << method.getArg(p).getType().getRpcName() << "::getValueName()"; cpp_file << ",\n" " ulxr_i18n(ULXR_PCHAR(\"Some descriptive comment about '" << method.getCppString(0, true, "") << "'.\"))); // TODO adjust comment\n"; } cpp_file << "}\n\n"; }
bool methodTest() { Class A(NULL, "A"); Class B(&A, "B"); ASSERT_NO_THROW(B.addMethod("nothing", doesNothing)); ASSERT_EQUALS("nothing", B.getMethod("nothing").name()); ASSERT_EQUALS("B", B.getMethod("nothing").getDeclaringClass()); Method m = B.getMethod("nothing"); Object* inst = A.newInstance(); Object* b_inst = B.newInstance(); ASSERT_THROW(MethodNotFound, m.invoke(inst)); ASSERT_NO_THROW(m.invoke(b_inst)); ASSERT_NO_THROW(A.addInstanceField("x", INT)); // set accessible must be zero but invoke must succeed ASSERT_NO_THROW(A.addMethod("goblin", goblinIsHere)); Object* obj = A.newInstance(); Field f = A.getField("x"); Class::setAccessible(true); ASSERT_EQUALS(f.getInt(obj), 0); Class::setAccessible(false); ASSERT_NO_THROW(obj->invokeMethod("goblin")); ASSERT_THROW(FieldNotAccessible, f.getInt(obj)); Class::setAccessible(true); ASSERT_EQUALS(f.getInt(obj), 7); /* delete inst; delete b_inst; delete obj;*/ return true; }
BytesPtr ExecutorDummy::run(MethodId const& id, BytesPtr srcArgs) { try { //updateTraffic(id, srcArgs->size()); if (id == makeMethodId(Interfaces::IDirect3DDevice9, Methods_IDirect3DDevice9::Present)) ++numFrames_; BytesPtr dstArgs = bytes::make(); Method method = methods_->getMethod(id); method.first(srcArgs, dstArgs); return dstArgs; } catch(std::exception const &e) { LogError(e.what()); Verify(false); } catch(...) { LogError("Unknown exception"); Verify(false); } }
Method Class::findMethod(string name, string vsig, string rsig, int static_) { Method m; if (!this->valid) { Method m; m.init(this->jvm, "can't call find method for invalid class"); return m; } m.jvm = this->jvm; m.cls = *this; m.name = name; m.vsig = vsig; m.rsig = rsig; m.static_ = static_; string sig_ = "(" + vsig + ")" + rsig; if (static_) { m.mid = this->jvm->env_->GetStaticMethodID(this->cls, name.c_str(), sig_.c_str()); } else { m.mid = this->jvm->env_->GetMethodID(this->cls, name.c_str(), sig_.c_str()); } if (m.mid) { m.init(this->jvm, ""); } else { m.init(this->jvm, "method(" + m.name + ") not found by sig:" + sig_); } return m; }
int main(int argc, const char* argv[]) { JvmEnv jenv; jenv.addClassPath("."); jenv.addClassPath("./tests"); jenv.addClassPath("/home/trapni/projects/jvmtoy/classpath-rt"); std::string className = argc == 2 ? argv[1] : "Test"; Class* c = jenv.getClass(className); if (!c) { fprintf(stderr, "Could not find class '%s'.\n", className.c_str()); return 1; } c->dump(); Method* method = c->findMethod("main"); int errors = 0; if (!method) { fprintf(stderr, "Could not find method '%s' in %s.\n", "main", c->name().c_str()); ++errors; } else { if (!(method->flags() & MethodFlags::Public)) { printf("main: must be public\n"); ++errors; } if (!(method->flags() & MethodFlags::Static)) { printf("main: must be static\n"); ++errors; } if (method->signature() != "([Ljava/lang/String;)V") { printf("main: invalid signature\n"); ++errors; } } if (!errors) { printf("entry method found\n"); } return 0; }
// Find all methods on this hierarchy that match this // method's erased (name, signature) bool visit() { PseudoScope* scope = PseudoScope::cast(current_data()); InstanceKlass* iklass = current_class(); Method* m = iklass->find_method(_method_name, _method_signature); // private interface methods are not candidates for default methods // invokespecial to private interface methods doesn't use default method logic // The overpasses are your supertypes' errors, we do not include them // future: take access controls into account for superclass methods if (m != NULL && !m->is_static() && !m->is_overpass() && (!iklass->is_interface() || m->is_public())) { if (_family == NULL) { _family = new StatefulMethodFamily(); } if (iklass->is_interface()) { StateRestorer* restorer = _family->record_method_and_dq_further(m); scope->add_mark(restorer); } else { // This is the rule that methods in classes "win" (bad word) over // methods in interfaces. This works because of single inheritance _family->set_target_if_empty(m); } } return true; }
bool MethodsList::removeMethodFromAST( Method& method ) { bool status = false; const char* method_key = method.getSignature().getMethodKey().getChars(); if ( (status = method.removeMethod( method_key )) ) { try { IEntry<IPosition<SourceToken> >* e = this->methodPositions->find( method_key ); delete this->methodPositions->remove( e ); } catch ( NoSuchElementException* ex ) { delete ex; } try { IEntry<Method>* e = this->methods->find( method_key ); delete this->methods->remove( e ); } catch ( NoSuchElementException* ex ) { delete ex; } } return status; }
void Class::dump() { printf("-----------------------------------------------\n"); printf("Version: %d.%d\n", major_, minor_); printf("This class: %s\n", thisClassName_.c_str()); printf("Super class: %s\n", superClassName_.c_str()); printf("Flags: %s\n", tos(flags_).c_str()); printf("Interface count: %zu\n", interfaces_.size()); printf("CONSTANT_POOL:\n"); for (int k = 1; k < constantPool.size(); ++k) { printf("\t[%d] %s\n", k, constantPool[k] ? constantPool[k]->to_s().c_str() : "null"); } printf("FIELDS: #%zu\n", fields_.size()); for (int k = 0; k < fields_.size(); ++k) { Field* field = fields_[k]; printf("\t[%d] ", k); field->dump(); } printf("METHODS: #%zu\n", methods_.size()); for (int k = 0; k < methods_.size(); ++k) { Method* method = methods_[k]; printf("\t[%d] ", k); method->dump(); } }
static void generateMethodDispatcher(CodeFile& f, Service* s, Method& m) { f.output("public static bool %s(bintalk.IReader __r__, %sProxy __p__)", m.getNameC(), s->getNameC()); f.indent("{"); for(size_t i = 0; i < m.fields_.size(); i++) { Field& field = m.fields_[i]; std::string tn; getFieldTypeName(field, tn); std::string dft; getFieldDefault(field, dft); f.output("%s %s= %s;", tn.c_str(), field.getNameC(), dft.c_str()); } generateFieldContainerDSCode(f, &m); f.listBegin(",", false, "return __p__.%s(", m.getNameC()); for(size_t i = 0; i < m.fields_.size(); i++) { Field& field = m.fields_[i]; f.listItem("%s", field.getNameC()); } f.listEnd(");"); f.recover("}"); }
void javaVFrame::print_value() const { Method* m = method(); InstanceKlass* k = m->method_holder(); tty->print_cr("frame( sp=" INTPTR_FORMAT ", unextended_sp=" INTPTR_FORMAT ", fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT ")", _fr.sp(), _fr.unextended_sp(), _fr.fp(), _fr.pc()); tty->print("%s.%s", k->internal_name(), m->name()->as_C_string()); if (!m->is_native()) { Symbol* source_name = k->source_file_name(); int line_number = m->line_number_from_bci(bci()); if (source_name != NULL && (line_number != -1)) { tty->print("(%s:%d)", source_name->as_C_string(), line_number); } } else { tty->print("(Native Method)"); } // Check frame size and print warning if it looks suspiciously large if (fr().sp() != NULL) { RegisterMap map = *register_map(); uint size = fr().frame_size(&map); #ifdef _LP64 if (size > 8*K) warning("SUSPICIOUSLY LARGE FRAME (%d)", size); #else if (size > 4*K) warning("SUSPICIOUSLY LARGE FRAME (%d)", size); #endif } }
// // resolve constant pool reference to a method // used for invokespecial // Method* resolve_special_method_env(Global_Env *env, Class_Handle curr_clss, unsigned index, bool raise_exn) { ASSERT_RAISE_AREA; Method* method = curr_clss->_resolve_method(env, index); if(!method) { assert(curr_clss->get_constant_pool().is_entry_in_error(index)); if (raise_exn) { exn_raise_object(curr_clss->get_constant_pool().get_error_cause(index)); } return NULL; } if(curr_clss->is_super() && is_class_extended_class(curr_clss->get_super_class(), method->get_class()) && method->get_name() != env->Init_String) { Method* result_meth; for(Class* clss = curr_clss->get_super_class(); clss; clss = clss->get_super_class()) { result_meth = clss->lookup_method(method->get_name(), method->get_descriptor()); if(result_meth) { method = result_meth; break; } } } if(method && !method_can_link_special(curr_clss, index, method, raise_exn)) return NULL; return method; } //resolve_special_method_env
void ModuleEmitter::createFunction(FuncDeclaration& funcDecl) { assert(!funcDecl.csym); IRState* irState = getCurrentIRState(); bool nested = false; bool member = false; Dsymbol* parent = funcDecl.parent; AggregateDeclaration* aggrDecl = handleNested(*this, funcDecl, nested, member); if (!aggrDecl) { aggrDecl = DEREF(irState).hasAggregateDecl(); } if (aggrDecl) { Aggregate& a = getAggregate(*aggrDecl); Method* m = createMethod(a.getBlock(), funcDecl, nested, parent); if (nested) { m->setNestedMember(member); m->generateBody(); } } else if (!handleTemplateMethod(*this, funcDecl)) { // All non-member functions are created at module scope, regardless of // the scope of their declaration in the source Method* method = createMethod(getBlock(), funcDecl); if (funcDecl.isStaticConstructor()) { assembly_.addModuleStaticCtor(DEREF(method)); } } }
Method* ModuleEmitter::createMethod(block& block, FuncDeclaration& funcDecl, bool nested, Dsymbol* parent ) { Method* method = NULL; if (funcDecl.csym == NULL) { method = new Method(funcDecl, block.depth(), nested, parent); block.add(*method); funcDecl.csym = method; } else if ((method = funcDecl.csym->isMethod()) != NULL) { // imported but not emitted? (imported methods are "hidden" in // the assembly block) if (DEREF(method->getOwner()).isAssembly()) { method = new Method(funcDecl, block.depth(), nested, parent); funcDecl.csym = method; block.add(*method); } } else { BackEnd::fatalError(funcDecl.loc, "decl has non-method symbol attached"); } return method; }
/* * Get Method Declaring Class * * For the method indicated by method, return the class that * defined it via declaring_class_ptr. * * REQUIRED Functionality. */ jvmtiError JNICALL jvmtiGetMethodDeclaringClass(jvmtiEnv* env, jmethodID method, jclass* declaring_class_ptr) { TRACE("GetMethodDeclaringClass called for " << method); SuspendEnabledChecker sec; /* * Check given env & current phase. */ jvmtiPhase phases[] = {JVMTI_PHASE_START, JVMTI_PHASE_LIVE}; CHECK_EVERYTHING(); if( !method ) return JVMTI_ERROR_INVALID_FIELDID; if( !declaring_class_ptr ) return JVMTI_ERROR_NULL_POINTER; Method* mtd = (Method*)method; Class* cls = mtd->get_class(); ObjectHandle hclss = struct_Class_to_java_lang_Class_Handle(cls); ObjectHandle newH = NewLocalRef(p_TLS_vmthread->jni_env, hclss); *declaring_class_ptr = (jclass)newH; return JVMTI_ERROR_NONE; }
void frame::pd_gc_epilog() { if (is_interpreted_frame()) { // set constant pool cache entry for interpreter Method* m = interpreter_frame_method(); *interpreter_frame_cpoolcache_addr() = m->constants()->cache(); } }
bool frame::is_interpreted_frame_valid(JavaThread* thread) const { // QQQ #ifdef CC_INTERP #else assert(is_interpreted_frame(), "Not an interpreted frame"); // These are reasonable sanity checks if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) { return false; } if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) { return false; } if (fp() + interpreter_frame_initial_sp_offset < sp()) { return false; } // These are hacks to keep us out of trouble. // The problem with these is that they mask other problems if (fp() <= sp()) { // this attempts to deal with unsigned comparison above return false; } // do some validation of frame elements // first the method Method* m = *interpreter_frame_method_addr(); // validate the method we'd find in this potential sender if (!m->is_valid_method()) return false; // stack frames shouldn't be much larger than max_stack elements if (fp() - sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) { return false; } // validate bci/bcx intptr_t bcx = interpreter_frame_bcx(); if (m->validate_bci_from_bcx(bcx) < 0) { return false; } // validate ConstantPoolCache* ConstantPoolCache* cp = *interpreter_frame_cache_addr(); if (cp == NULL || !cp->is_metaspace_object()) return false; // validate locals address locals = (address) *interpreter_frame_locals_addr(); if (locals > thread->stack_base() || locals < (address) fp()) return false; // We'd have to be pretty unlucky to be mislead at this point #endif // CC_INTERP return true; }