Ejemplo n.º 1
0
QMetaMethod QpMetaObject::method(QString signature, const QpMetaProperty &property) const
{
    QString propertyName = property.name();
    propertyName[0] = propertyName.at(0).toTitleCase();
    QString reverseClassName = property.reverseClassName();
    QMetaMethod method = findMethod(signature.arg(propertyName).arg(reverseClassName));


    if (method.isValid())
        return method;

    QString reverseClassNameWithoutNamespaces = removeNamespaces(reverseClassName);
    if (reverseClassNameWithoutNamespaces == reverseClassName)
        return QMetaMethod();


    method = findMethod(signature.arg(propertyName).arg(reverseClassNameWithoutNamespaces));
    if (method.isValid())
        return method;

    Q_ASSERT_X(false, Q_FUNC_INFO,
               QString("No such method '%1::%2'")
               .arg(data->metaObject.className())

               .arg(signature.arg(propertyName).arg(reverseClassName)).toLatin1());
    return QMetaMethod();
}
Ejemplo n.º 2
0
Object *classlibThreadPreInit(Class *thread_class, Class *thrdGrp_class) {
    MethodBlock *system_init_mb, *main_init_mb;
    FieldBlock *thread_status_fb, *eetop_fb;
    Object *system, *main, *main_name;

    init_mb_with_name = findMethod(thread_class, SYMBOL(object_init),
                           SYMBOL(_java_lang_ThreadGroup_java_lang_String__V));

    init_mb_no_name = findMethod(thread_class, SYMBOL(object_init),
                         SYMBOL(_java_lang_ThreadGroup_java_lang_Runnable__V));

    thread_status_fb = findField(thread_class, SYMBOL(threadStatus),
                                               SYMBOL(I));

    eetop_fb = findField(thread_class, SYMBOL(eetop), SYMBOL(J));

    system_init_mb = findMethod(thrdGrp_class, SYMBOL(object_init),
                                               SYMBOL(___V));

    main_init_mb = findMethod(thrdGrp_class, SYMBOL(object_init),
                           SYMBOL(_java_lang_ThreadGroup_java_lang_String__V));

    if(init_mb_with_name   == NULL || init_mb_no_name == NULL ||
          system_init_mb   == NULL || main_init_mb    == NULL ||
          thread_status_fb == NULL || eetop_fb        == NULL)
        return NULL;

    CLASS_CB(thread_class)->flags |= JTHREAD;

    thread_status_offset = thread_status_fb->u.offset;
    eetop_offset = eetop_fb->u.offset;

    if((system = allocObject(thrdGrp_class)) == NULL)
        return NULL;

    executeMethod(system, system_init_mb);
    if(exceptionOccurred())
        return NULL;

    if((main = allocObject(thrdGrp_class)) == NULL ||
       (main_name = Cstr2String("main")) == NULL)
        return NULL;

    executeMethod(main, main_init_mb, system, main_name);
    if(exceptionOccurred())
        return NULL;

    return main;
}
Ejemplo n.º 3
0
void TestCppBehaviour::Update()
{
    if (++m_frame % 120 == 0) {
        //// crash test
        //*(int*)nullptr = 0;

        cpsDebugPrint("TestCppBehaviour::Update()\n");
        cpsDebugPrint("name: %s\n", trans.get_name().toUTF8());
        if (cpsMethod method = findMethod("ThisFunctionWillBeCalledFromCpp")) {
            method.invoke(*this, nullptr);
        }

        {
            m_v3v->x += 1.0f;
            m_v3v->y += 2.0f;
            m_v3v->z += 3.0f;
        }
        {
            Vector3 pos = trans.get_position();
            pos.x += 0.1f;
            pos.y += 0.1f;
            pos.z += 0.1f;
            trans.set_position(pos);
            trans.Translate(Vector3(0.0f, 0.1f, 0.2f));
        }
    }
    {
        trans.Rotate(Vector3(0.0f, 1.0f, 0.0f), 1.0f);
    }
}
Ejemplo n.º 4
0
  std::string MetaObjectPrivate::generateErrorString(const std::string& signature,
                                                     const std::string& resolvedSignature,
                                                     const std::vector<std::pair<MetaMethod, float> >& candidates,
                                                     int error,
                                                     bool logError) const
  {
    std::stringstream ss;

    if (error == -1 && candidates.size() != 0) {
      qiLogError() << "Broken error handling in generateErrorString";
      logError = 1;
    }
    switch (error) {
      case -1: {
        ss << "Can't find method: " << signature << " (resolved to '" << resolvedSignature << "')" << std::endl;
        std::vector<MetaMethod> mmv = findMethod(qi::signatureSplit(signature)[1]);
        displayMeths(ss, mmv);
        break;
      }
      case -2:
        ss << "Arguments types did not match for " << signature  << " (resolved to '" << resolvedSignature << "')" << ":" << std::endl;
        displayCandidates(ss, candidates);
        break;
      case -3:
        ss << "Ambiguous overload for " << signature  << " (resolved to '" << resolvedSignature << "')" << ":" << std::endl;
        displayCandidates(ss, candidates);
        break;
      default:
        qiLogError() << "Invalid error id for generateErrorString";
    }
    if (logError)
      qiLogError() << ss.str();
    return ss.str();
  }
Ejemplo n.º 5
0
  std::vector<MetaObject::CompatibleMethod> MetaObjectPrivate::findCompatibleMethod(const std::string &nameOrSignature)
  {
    boost::recursive_mutex::scoped_lock sl(_methodsMutex);
    std::vector<MetaObject::CompatibleMethod>         ret;
    std::string cname(nameOrSignature);

    //no signature specified fallback on findMethod
    if (cname.find(':') == std::string::npos)
    {
      std::vector<MetaMethod> r = findMethod(cname);
      ret.reserve(r.size());
      for (unsigned i=0; i<r.size(); ++i)
        ret.push_back(std::make_pair(r[i], 1.0f));
      return ret;
    }

    std::vector<std::string> sigsorig = qi::signatureSplit(nameOrSignature);
    if (sigsorig[1].empty())
      return ret;

    Signature sresolved(sigsorig[2]);

    for (auto& method: _methods) {
      const qi::MetaMethod& mm = method.second;

      if (sigsorig[1] != mm.name())
        continue;
      float score = sresolved.isConvertibleTo(Signature(mm.parametersSignature()));
      if (score)
        ret.push_back(std::make_pair(mm, score));
    }
    return ret;
  }
Ejemplo n.º 6
0
WrenForeignClassMethods bindBuiltInForeignClass(
    WrenVM* vm, const char* moduleName, const char* className)
{
  WrenForeignClassMethods methods = { NULL, NULL };

  ModuleRegistry* module = findModule(moduleName);
  if (module == NULL) return methods;

  ClassRegistry* clas = findClass(module, className);
  if (clas == NULL) return methods;

  methods.allocate = findMethod(clas, true, "<allocate>");
  methods.finalize = findMethod(clas, true, "<finalize>");

  return methods;
}
Ejemplo n.º 7
0
/**
 * Lookup a method given class, name and signature.
 *
 * @param cls the class where to start search
 * @param name name of the method being searched
 * @param sig signature of the method being searched
 * @param einfo struct errorInfo
 *
 * @throws OutOfMemoryError 
 *
 * @return struct _jmethodID of the method being searched or 0 in case of an error
 */
Method*
lookupClassMethod(Hjava_lang_Class* cls, const char* name, const char* sig, bool declared, errorInfo *einfo)
{
	Method *meth;
	Utf8Const *name_utf8, *sig_utf8;

	assert(cls != NULL);
	assert(name != NULL);
	assert(sig != NULL);

	name_utf8 = utf8ConstFromString(name);
	if (!name_utf8) {
		postOutOfMemory(einfo);
		return NULL;
	}
	sig_utf8 = utf8ConstFromString(sig);
	if (!sig_utf8) {
		utf8ConstRelease(name_utf8);
		postOutOfMemory(einfo);
		return NULL;
	}
	if (declared)
	  meth = KaffeVM_findDeclaredMethod(cls, name_utf8, sig_utf8, einfo);
	else
	  meth = findMethod(cls, name_utf8, sig_utf8, einfo);
	utf8ConstRelease(name_utf8);
	utf8ConstRelease(sig_utf8);
	return(meth);
}
Ejemplo n.º 8
0
 SoraRTTIType* SoraRTTIClassDescriptor::invoke( const std::string& name, void* obj, void* params[] )
 {
     SoraRTTIMethodDescriptor* method = findMethod( name );
     if( method )
         return method->invoke( obj, params );
     return NULL;
 }
Ejemplo n.º 9
0
static int initAnnotation() {
    Class *enum_cls, *map_cls, *anno_inv_cls, *obj_ary_cls;
    Class *anno_ary_cls, *dbl_anno_ary_cls;

    enum_cls = findSystemClass("java/lang/Enum");
    map_cls = findSystemClass("java/util/HashMap");
    anno_inv_cls = findSystemClass("sun/reflect/annotation/Annotation"
                                   "InvocationHandler");

    obj_ary_cls = findArrayClass("[Ljava/lang/Object;");
    anno_ary_cls = findArrayClass("[Ljava/lang/annotation/Annotation;");
    dbl_anno_ary_cls = findArrayClass("[[Ljava/lang/annotation/Annotation;");

    if(!enum_cls || !map_cls || !anno_inv_cls || !obj_ary_cls 
                 || !anno_ary_cls || !dbl_anno_ary_cls)
        return FALSE;

    map_init_mb = findMethod(map_cls, SYMBOL(object_init), SYMBOL(___V));
    map_put_mb = findMethod(map_cls, SYMBOL(put),
                            newUtf8("(Ljava/lang/Object;Ljava/lang/Object;)"
                                    "Ljava/lang/Object;"));

    anno_create_mb = findMethod(anno_inv_cls, newUtf8("create"),
                                newUtf8("(Ljava/lang/Class;Ljava/util/Map;)"
                                        "Ljava/lang/annotation/Annotation;"));

    enum_valueof_mb = findMethod(enum_cls, newUtf8("valueOf"),
                                 newUtf8("(Ljava/lang/Class;Ljava/lang/String;)"
                                         "Ljava/lang/Enum;"));

    if(!map_init_mb || !map_put_mb || !anno_create_mb || !enum_valueof_mb) {

        /* FindMethod doesn't throw an exception... */
        signalException(java_lang_InternalError,
                        "Expected field/method doesn't exist");
        return FALSE;
    }

    registerStaticClassRefLocked(&enum_class, enum_cls);
    registerStaticClassRefLocked(&map_class, map_cls);
    registerStaticClassRefLocked(&anno_inv_class, anno_inv_cls);
    registerStaticClassRefLocked(&obj_array_class, obj_ary_cls);
    registerStaticClassRefLocked(&anno_array_class, anno_ary_cls);
    registerStaticClassRefLocked(&dbl_anno_array_class, dbl_anno_ary_cls);

    return anno_inited = TRUE;
}
Ejemplo n.º 10
0
void SignalSlotConnection::tryConnect()
{
    Q_D(SignalSlotConnection);
    if(source() && destination() && !d->_signal.isNull() && !d->_slot.isNull())
    {
        QMetaMethod slot = findMethod(destination(), d->_slot);
        QMetaMethod signal = findMethod(source(), d->_signal);
        d->_internalConnection = QObject::connect(source(), signal,
                                                       destination(), slot,
                         (Qt::ConnectionType)d->_connectionType);
        bool success = d->_internalConnection;
        if(!success)
        {
            qDebug() << QString("DirectConnection: could not connect %1 with %2").arg(d->_signal).arg(d->_slot);
        }
    }
}
Ejemplo n.º 11
0
Jvm::JMethod Jvm::findStaticMethod(const MethodSignature& signature)
{
  jmethodID id = findMethod(signature.clazz,
                            signature.name,
                            signature.returnType,
                            signature.parameters,
                            true);
  return Jvm::JMethod(signature.clazz, id);
}
Ejemplo n.º 12
0
Jvm::JConstructor Jvm::findConstructor(const ConstructorFinder& signature)
{
  jmethodID id =
      findMethod(signature.type,
                 "<init>",
                 voidClass,
                 signature.parameters,
                 false);
  return Jvm::JConstructor(signature.type, id);
}
Ejemplo n.º 13
0
Jvm::Method Jvm::findMethod(const MethodSignature& signature)
{
  jmethodID id = findMethod(
      signature.clazz,
      signature.name,
      signature.returnType,
      signature.parameters,
      false);

  return Jvm::Method(signature.clazz, id);
}
Ejemplo n.º 14
0
Jvm::Constructor Jvm::findConstructor(const ConstructorFinder& finder)
{
  jmethodID id = findMethod(
      finder.clazz,
      "<init>",
      voidClass,
      finder.parameters,
      false);

  return Jvm::Constructor(finder.clazz, id);
}
Ejemplo n.º 15
0
 inline void invokeRowsAboutToBeInserted(const QModelIndex &source_parent, int start, int end)
 {
     Q_Q(KRecursiveFilterProxyModel);
     static const QMetaMethod m = findMethod("_q_sourceRowsAboutToBeInserted(QModelIndex,int,int)");
     bool success = m.invoke(q, Qt::DirectConnection,
                             Q_ARG(QModelIndex, source_parent),
                             Q_ARG(int, start),
                             Q_ARG(int, end));
     Q_UNUSED(success);
     Q_ASSERT(success);
 }
Ejemplo n.º 16
0
void SignalSlotConnection::tryDisconnect()
{
    Q_D(SignalSlotConnection);
    if(source() && destination() && !d->_signal.isNull() && !d->_slot.isNull())
    {
        QMetaMethod slot = findMethod(destination(), d->_slot);
        QMetaMethod signal = findMethod(source(), d->_signal);
        bool success = QObject::disconnect(source(), signal,
                                           destination(), slot);
        if(success)
        {
            d->_internalConnection = QMetaObject::Connection();
            qDebug() << QString("Disconnected: %1 -> %2").arg(source()->metaObject()->className()).
                        arg(destination()->metaObject()->className());
        }
        if(!success)
        {
            qDebug() << QString("DirectConnection: could not disconnect %1 with %2").arg(d->_signal).arg(d->_slot);
        }
    }
}
Ejemplo n.º 17
0
 // Convenience methods for invoking the QSFPM Q_SLOTS. Those slots must be invoked with invokeMethod
 // because they are Q_PRIVATE_SLOTs
 inline void invokeDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>())
 {
     Q_Q(KRecursiveFilterProxyModel);
     bool success = false;
     if (passRolesToDataChanged()) {
         // required for Qt 5.5 and upwards, see commit f96baeb75fc in qtbase
         static const QMetaMethod m = findMethod("_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)");
         success = m.invoke(q, Qt::DirectConnection,
                            Q_ARG(QModelIndex, topLeft),
                            Q_ARG(QModelIndex, bottomRight),
                            Q_ARG(QVector<int>, roles));
     } else {
         // backwards compatibility
         static const QMetaMethod m = findMethod("_q_sourceDataChanged(QModelIndex,QModelIndex)");
         success = m.invoke(q, Qt::DirectConnection,
                            Q_ARG(QModelIndex, topLeft),
                            Q_ARG(QModelIndex, bottomRight));
     }
     Q_UNUSED(success);
     Q_ASSERT(success);
 }
Ejemplo n.º 18
0
WrenForeignMethodFn bindBuiltInForeignMethod(
    WrenVM* vm, const char* moduleName, const char* className, bool isStatic,
    const char* signature)
{
  // TODO: Assert instead of return NULL?
  ModuleRegistry* module = findModule(moduleName);
  if (module == NULL) return NULL;

  ClassRegistry* clas = findClass(module, className);
  if (clas == NULL) return NULL;

  return findMethod(clas, isStatic, signature);
}
Ejemplo n.º 19
0
int classlibThreadPostInit() {
    Class *system = findSystemClass(SYMBOL(java_lang_System));

    if(system != NULL) {
        MethodBlock *init = findMethod(system, SYMBOL(initializeSystemClass),
                                               SYMBOL(___V));
        if(init != NULL) {
            executeStaticMethod(system, init);
            return !exceptionOccurred();
        }
    }

    return FALSE;
}
Ejemplo n.º 20
0
static Method* getMethod(Env* env, Class* clazz, const char* name, const char* desc) {
    if (!strcmp("<init>", name) || !strcmp("<clinit>", name)) {
        // Constructors and static initializers are not inherited so we shouldn't check with the superclasses.
        return findMethod(env, clazz, name, desc);
    }

    Class* c = clazz;
    for (c = clazz; c != NULL; c = c->superclass) {
        Method* method = findMethod(env, c, name, desc);
        if (rvmExceptionCheck(env)) return NULL;
        if (method) return method;
    }

    /*
     * Check with interfaces.
     * TODO: Should we really do this? Does the JNI GetMethodID() function do this?
     */
    for (c = clazz; c != NULL; c = c->superclass) {
        Interface* interfaze = rvmGetInterfaces(env, c);
        if (rvmExceptionCheck(env)) return NULL;
        for (; interfaze != NULL; interfaze = interfaze->next) {
            Method* method = getMethod(env, interfaze->interfaze, name, desc);
            if (rvmExceptionCheck(env)) return NULL;
            if (method) return method;
        }
    }

    if (CLASS_IS_INTERFACE(clazz)) {
        /*
         * Class is an interface so check with java.lang.Object.
         * TODO: Should we really do this? Does the JNI GetMethodID() function do this?
         */
        return getMethod(env, java_lang_Object, name, desc);
    }

    return NULL;
}
Ejemplo n.º 21
0
Archivo: invoke.c Proyecto: ahua/java
/*
 * Resolve a method by recursively searching through the method table
 * of the given class and its superclasses.
 */
static Ref resolveMethod(Ref type, Ref name, Ref descriptor) {
    Ref m = NULL;         // method
    Ref t = type;         // type
    while (t != NULL && m == NULL) {
        m = findMethod(t, name, descriptor);
        t = getRef(t, TYPE_SUPER_TYPE);
    }

    // throw exception if not found
    if (m == NULL) {
        printf("Need to throw proper exception here, method not found!!!\n");
        exit(1);
    }
    return m;
}
Ejemplo n.º 22
0
void exitVM(int status) {
    main_exited = TRUE;

    /* Execute System.exit() to run any registered shutdown hooks.
       In the unlikely event that System.exit() can't be found, or
       it returns, fall through and exit. */

    if(!VMInitialising()) {
        Class *system = findSystemClass(SYMBOL(java_lang_System));
        if(system) {
            MethodBlock *exit = findMethod(system, SYMBOL(exit), SYMBOL(_I__V));
            if(exit) {
                DummyFrame dummy;
                executeStaticMethod(&dummy, system, exit, status);
            }
        }
    }

    jamvm_exit(status);
}
Ejemplo n.º 23
0
Nuria::Resource::InvokeResultState Nuria::ObjectWrapperResourcePrivate::invoke (const QString &slot,
                                                                                const QVariantMap &arguments,
                                                                                Resource::InvokeCallback callback) {
	// Find slot
	int idx = findMethod (QMetaMethod::Slot, slot, arguments);
	if (idx < 0) {
		return (idx == UnknownArguments) ? Resource::BadArgumentError : Resource::UnknownError;
	}
	
	// 
	QMetaMethod method = this->meta->method (idx);
	QByteArray signature = method.methodSignature ();
	QVariantList args = argumentsToList (this->methods.value (idx), arguments);
	
	// Invoke
	Callback invoker (this->object, signature.constData () - 1);
	QVariant result = invoker.invoke (args);
	
	// Done.
	callback (Resource::Success, result);
	return Resource::Success;
}
Ejemplo n.º 24
0
int classlibThreadPostInit() {
    Class *system;

#ifdef JSR292
    /* Initialise lock used in Method Handle resolution - this
       must be done before any invokedynamic instruction is executed */
    initVMLock(resolve_lock);
#endif

    /* Initialise System class */
    system = findSystemClass(SYMBOL(java_lang_System));
    if(system != NULL) {
        MethodBlock *init = findMethod(system, SYMBOL(initializeSystemClass),
                                               SYMBOL(___V));
        if(init != NULL) {
            executeStaticMethod(system, init);
            return !exceptionOccurred();
        }
    }

    return FALSE;
}
Ejemplo n.º 25
0
Archivo: jni.c Proyecto: Liam1206/jamvm
int classlibInitialiseJNI() {
    FieldBlock *buffCap_fb, *buffAddr_fb, *rawdata_fb;
    Class *buffer_class;

    /* Cache class and method/fields for JNI 1.4 NIO support */

    buffer_class = findSystemClass0(SYMBOL(java_nio_Buffer));
    buffImpl_class = findSystemClass0(
                         SYMBOL(java_nio_DirectByteBufferImpl_ReadWrite));
    rawdata_class = findSystemClass0(sizeof(uintptr_t) == 4
                                            ? SYMBOL(gnu_classpath_Pointer32)
                                            : SYMBOL(gnu_classpath_Pointer64));

    if(buffer_class == NULL || buffImpl_class == NULL || rawdata_class == NULL)
        return FALSE;

    buffImpl_init_mb = findMethod(buffImpl_class, SYMBOL(object_init),
                      SYMBOL(_java_lang_Object_gnu_classpath_Pointer_III__V));

    buffCap_fb = findField(buffer_class, SYMBOL(cap), SYMBOL(I));
    rawdata_fb = findField(rawdata_class, SYMBOL(data),
                           sizeof(uintptr_t) == 4 ? SYMBOL(I) : SYMBOL(J));
    buffAddr_fb = findField(buffer_class, SYMBOL(address),
                            SYMBOL(sig_gnu_classpath_Pointer));

    if(buffImpl_init_mb == NULL || buffCap_fb == NULL || rawdata_fb == NULL
                                || buffAddr_fb == NULL)
        return FALSE;

    registerStaticClassRef(&buffImpl_class);
    registerStaticClassRef(&rawdata_class);

    buffCap_offset = buffCap_fb->u.offset;
    buffAddr_offset = buffAddr_fb->u.offset;
    rawdata_offset = rawdata_fb->u.offset;

    return TRUE;
}
Ejemplo n.º 26
0
Archivo: excep.c Proyecto: OPSF/uClinux
void initialiseException() {
    FieldBlock *bcktrce;
    int i;

    ste_class = findSystemClass0(SYMBOL(java_lang_StackTraceElement));
    ste_array_class = findArrayClass(SYMBOL(array_java_lang_StackTraceElement));
    vmthrow_class = findSystemClass0(SYMBOL(java_lang_VMThrowable));
    throw_class = findSystemClass0(SYMBOL(java_lang_Throwable));
    bcktrce = findField(vmthrow_class, SYMBOL(backtrace), SYMBOL(sig_java_lang_Object));
    vmthrow_init_mb = findMethod(ste_class, SYMBOL(object_init),
                         SYMBOL(_java_lang_String_I_java_lang_String_java_lang_String_Z__V));

    if((bcktrce == NULL) || (vmthrow_init_mb == NULL)) {
        jam_fprintf(stderr, "Error initialising VM (initialiseException)\n");
        exitVM(1);
    }

    CLASS_CB(vmthrow_class)->flags |= VMTHROWABLE;
    backtrace_offset = bcktrce->offset;

    registerStaticClassRef(&ste_class);
    registerStaticClassRef(&ste_array_class);
    registerStaticClassRef(&vmthrow_class);
    registerStaticClassRef(&throw_class);

    /* Load and register the exceptions used within the VM.
       These are preloaded to speed up access.  The VM will
       abort if any can't be loaded */

    for(i = 0; i < MAX_EXCEPTION_ENUM; i++) {
        exceptions[i] = findSystemClass0(symbol_values[exception_symbols[i]]);
        registerStaticClassRef(&exceptions[i]);
    }

    inited = TRUE;
}
Ejemplo n.º 27
0
int classlibInitReflection() {
    Class *cons_ref_cls, *mthd_ref_cls, *fld_ref_cls;

    FieldBlock *cons_slot_fb, *cons_class_fb, *cons_param_fb;
    FieldBlock *mthd_slot_fb, *mthd_class_fb, *mthd_ret_fb, *mthd_param_fb;
    FieldBlock *fld_slot_fb, *fld_class_fb;

    cons_ref_cls = findSystemClass(SYMBOL(java_lang_reflect_Constructor));
    mthd_ref_cls = findSystemClass(SYMBOL(java_lang_reflect_Method));
    fld_ref_cls = findSystemClass(SYMBOL(java_lang_reflect_Field));

    if(!cons_ref_cls || !mthd_ref_cls || !fld_ref_cls)
        return FALSE;

    cons_slot_fb  = findField(cons_ref_cls, SYMBOL(slot), SYMBOL(I));
    cons_class_fb = findField(cons_ref_cls, SYMBOL(clazz),
                                            SYMBOL(sig_java_lang_Class));
    cons_param_fb = findField(cons_ref_cls, SYMBOL(parameterTypes),
                                            SYMBOL(array_java_lang_Class));

    mthd_slot_fb  = findField(mthd_ref_cls, SYMBOL(slot), SYMBOL(I));
    mthd_class_fb = findField(mthd_ref_cls, SYMBOL(clazz),
                                            SYMBOL(sig_java_lang_Class));
    mthd_ret_fb   = findField(mthd_ref_cls, SYMBOL(returnType),
                                            SYMBOL(sig_java_lang_Class));
    mthd_param_fb = findField(mthd_ref_cls, SYMBOL(parameterTypes),
                                            SYMBOL(array_java_lang_Class));

    fld_slot_fb   = findField(fld_ref_cls,  SYMBOL(slot), SYMBOL(I));
    fld_class_fb  = findField(fld_ref_cls,  SYMBOL(clazz),
                                            SYMBOL(sig_java_lang_Class));

    fld_init_mb = findMethod(fld_ref_cls, SYMBOL(object_init),
                             SYMBOL(java_lang_reflect_field_init_sig));

    cons_init_mb = findMethod(cons_ref_cls, SYMBOL(object_init),
                              SYMBOL(java_lang_reflect_cons_init_sig));

    mthd_init_mb = findMethod(mthd_ref_cls, SYMBOL(object_init),
                              SYMBOL(java_lang_reflect_mthd_init_sig));

    mthd_invoke_mb = findMethod(mthd_ref_cls, SYMBOL(invoke),
                                SYMBOL(java_lang_reflect_mthd_invoke_sig));

    if(!fld_init_mb    || !cons_init_mb  || !mthd_init_mb  ||
       !cons_slot_fb   || !cons_class_fb || !cons_param_fb ||
       !mthd_slot_fb   || !mthd_class_fb || !mthd_ret_fb   ||
       !mthd_param_fb  || !fld_slot_fb   || !fld_class_fb  ||
       !mthd_invoke_mb)  {
        /* Find Field/Method doesn't throw an exception... */
        signalException(java_lang_InternalError,
                        "Expected reflection method/field doesn't exist");
        return FALSE;
    }

    cons_slot_offset = cons_slot_fb->u.offset; 
    cons_class_offset = cons_class_fb->u.offset; 
    cons_param_offset = cons_param_fb->u.offset; 
    mthd_slot_offset = mthd_slot_fb->u.offset; 
    mthd_class_offset = mthd_class_fb->u.offset; 
    mthd_ret_offset = mthd_ret_fb->u.offset; 
    mthd_param_offset = mthd_param_fb->u.offset; 
    fld_slot_offset = fld_slot_fb->u.offset; 
    fld_class_offset = fld_class_fb->u.offset; 

    registerStaticClassRefLocked(&cons_reflect_class, cons_ref_cls);
    registerStaticClassRefLocked(&method_reflect_class, mthd_ref_cls);
    registerStaticClassRefLocked(&field_reflect_class, fld_ref_cls);

    return TRUE;
}
Ejemplo n.º 28
0
void RSCParse::parse()
{
	findSuperAndClass();
	findProperties();
	findMethod();
}
Ejemplo n.º 29
0
void initialiseThreadStage2(InitArgs *args) {
    Object *java_thread;
    Class *thrdGrp_class;
    MethodBlock *run, *remove_thread;
    FieldBlock *group, *priority, *root, *threadId;
    FieldBlock *vmThread = NULL, *thread = NULL;
    FieldBlock *vmData, *daemon, *name;

    /* Load thread class and register reference for compaction threading */
    thread_class = findSystemClass0(SYMBOL(java_lang_Thread));
    registerStaticClassRef(&thread_class);

    if(thread_class != NULL) {
        vmThread = findField(thread_class, SYMBOL(vmThread), SYMBOL(sig_java_lang_VMThread));
        daemon = findField(thread_class, SYMBOL(daemon), SYMBOL(Z));
        name = findField(thread_class, SYMBOL(name), SYMBOL(sig_java_lang_String));
        group = findField(thread_class, SYMBOL(group), SYMBOL(sig_java_lang_ThreadGroup));
        priority = findField(thread_class, SYMBOL(priority), SYMBOL(I));
        threadId = findField(thread_class, SYMBOL(threadId), SYMBOL(J));

        init_mb = findMethod(thread_class, SYMBOL(object_init),
                             SYMBOL(_java_lang_VMThread_java_lang_String_I_Z__V));
        run = findMethod(thread_class, SYMBOL(run), SYMBOL(___V));

        vmthread_class = findSystemClass0(SYMBOL(java_lang_VMThread));
        CLASS_CB(vmthread_class)->flags |= VMTHREAD;

        /* Register class reference for compaction threading */
        registerStaticClassRef(&vmthread_class);

        if(vmthread_class != NULL) {
            thread = findField(vmthread_class, SYMBOL(thread), SYMBOL(sig_java_lang_Thread));
            vmData = findField(vmthread_class, SYMBOL(vmData), SYMBOL(I));
        }
    }

    /* findField and findMethod do not throw an exception... */
    if((init_mb == NULL) || (vmData == NULL) || (run == NULL) || (daemon == NULL) ||
       (name == NULL) || (group == NULL) || (priority == NULL) || (vmThread == NULL) ||
       (thread == NULL) || (threadId == NULL))
        goto error;

    vmthread_offset = vmThread->offset;
    thread_offset = thread->offset;
    vmData_offset = vmData->offset;
    daemon_offset = daemon->offset;
    group_offset = group->offset;
    priority_offset = priority->offset;
    threadId_offset = threadId->offset;
    name_offset = name->offset;
    run_mtbl_idx = run->method_table_index;

    /* Initialise the Java-level thread objects for the main thread */
    java_thread = initJavaThread(&main_thread, FALSE, "main");

    /* Main thread is now sufficiently setup to be able to run the thread group
       initialiser.  This is essential to create the root thread group */
    thrdGrp_class = findSystemClass(SYMBOL(java_lang_ThreadGroup));

    root = findField(thrdGrp_class, SYMBOL(root), SYMBOL(sig_java_lang_ThreadGroup));

    addThread_mb = findMethod(thrdGrp_class, SYMBOL(addThread),
                                             SYMBOL(_java_lang_Thread_args__void));

    remove_thread = findMethod(thrdGrp_class, SYMBOL(removeThread),
                                              SYMBOL(_java_lang_Thread_args__void));

    /* findField and findMethod do not throw an exception... */
    if((root == NULL) || (addThread_mb == NULL) || (remove_thread == NULL))
        goto error;

    rmveThrd_mtbl_idx = remove_thread->method_table_index;

    /* Add the main thread to the root thread group */
    INST_DATA(java_thread)[group_offset] = root->static_value;
    {
        DummyFrame dummy;
        executeMethod(&dummy, ((Object*)root->static_value), addThread_mb, java_thread);
    }

    // dyn
    INST_DATA(java_thread)[vmthread_offset] = 0;

    /* Setup signal handling.  This will be inherited by all
       threads created within Java */
    initialiseSignals();

    /* Create the signal handler thread.  It is responsible for
       catching and handling SIGQUIT (thread dump) and SIGINT
       (user-termination of the VM, e.g. via Ctrl-C).  Note it
       must be a valid Java-level thread as it needs to run the
       shutdown hooks in the event of user-termination */
    createVMThread("Signal Handler", dumpThreadsLoop);

    return;

error:
    jam_fprintf(stderr, "Error initialising VM (initialiseMainThread)\nCheck "
                        "the README for compatible versions of GNU Classpath\n");
    printException();
    exitVM(1);
}
Ejemplo n.º 30
0
/**
 * Creates a new instance of Java PcapIf object, intializes all of its fields
 * from pcap_if_t structure and add the resulting element to jlist which is
 * a Java java.util.List object. The method id is cached but has to discovered
 * upon the first entry into findDevsAll since we don't know exactly the type
 * of actual object implementing the List interface. Could be ArrayList,
 * LinkedList or some other custom list. So that is the reason for the dynamic
 * methodID lookup. We pass the ID along to reuse it through out the life of
 * this recursive scan.
 *
 * @param obj Pcap
 * @param jlist java.util.list to which we will add this PcapIf element
 * @param MID_add cached dynamic method ID of the "add" method
 * @param ifp pcap_if_t structure to use in construction of java counter part
 * @return PcapIf
 */
jobject newPcapIf(JNIEnv *env, jobject jlist, jmethodID MID_add, pcap_if_t *ifp) {
	jobject js;

	// Invoke new PcapIf()
	jobject obj = env->NewObject(pcapIfClass, pcapIfConstructorMID);

	/*
	 * Initialize PcapIf.next field. Also add the new PcapIf object that went
	 * into the field to the use supplied jlist.
	 */
	if (ifp->next != NULL) {
		jobject jpcapif = newPcapIf(env, jlist, MID_add, ifp->next);
		if (jpcapif == NULL) {
			return NULL; // Out of memory exception already thrown
		}

		env->SetObjectField(obj, pcapIfNextFID, jpcapif);
		if (env->CallBooleanMethod(jlist, MID_add, jpcapif) == JNI_FALSE) {
			env->DeleteLocalRef(jpcapif);
			return NULL; // Failed to add to the list
		}

		env->DeleteLocalRef(jpcapif);
	} else {
		env->SetObjectField(obj, pcapIfNextFID, NULL);
	}

	/**
	 * Assign PcapIf.name string field.
	 */
	if (ifp->name != NULL) {

		js = env->NewStringUTF(ifp->name);
		if (js == NULL) {
			return NULL; // Out of memory exception already thrown
		}

		env->SetObjectField(obj, pcapIfNameFID, js);

		env->DeleteLocalRef(js);

	} else {
		env->SetObjectField(obj, pcapIfNameFID, NULL);
	}

	/**
	 * Assign PcapIf.description string field.
	 */
	if (ifp->description != NULL) {
		js = env->NewStringUTF(ifp->description);
		if (js == NULL) {
			return NULL; // Out of memory exception already thrown
		}
		env->SetObjectField(obj, pcapIfDescriptionFID, js);

		env->DeleteLocalRef(js);
	} else {
		env->SetObjectField(obj, pcapIfDescriptionFID, NULL);
	}

	/**
	 * Add all addresses found in pcap_if.address linked list of sockaddr to
	 * the already Java allocated list in the PcapIf.addresses field.
	 */
	if (ifp->addresses != NULL) {

		// Lookup field and the List object from PcapIf.addresses field
		jobject jaddrlist = env->GetObjectField(obj, pcapIfAddressesFID);
		if (jaddrlist == NULL) {
			return NULL; // Exception already thrown
		}

		// Lookup List.add method ID within the object, can't be static as this
		// is a interface lookup, not a known object type implementing the
		// interface
		jmethodID MID_addr_add = findMethod(env, jaddrlist, "add",
				"(Ljava/lang/Object;)Z");
		if (MID_addr_add == NULL) {
			env->DeleteLocalRef(jaddrlist);
			return NULL; // Exception already thrown
		}

		// Process the structure and get the next addr
		jobject jaddr = newPcapAddr(env, jaddrlist, MID_addr_add, ifp->addresses);
		if (jaddr == NULL) {
			env->DeleteLocalRef(jaddrlist);
			return NULL; // Out of memory exception already thrown
		}

		// Call on List.add method to add our new PcapAddr object
		if (env->CallBooleanMethod(jaddrlist, MID_addr_add, jaddr) == JNI_FALSE) {
			env->DeleteLocalRef(jaddrlist);
			env->DeleteLocalRef(jaddr);
			return NULL; // Failed to add to the list
		}

		// Release local resources
		env->DeleteLocalRef(jaddr);
		env->DeleteLocalRef(jaddrlist);
	}

	env->SetIntField(obj, pcapIfFlagsFID, (jint) ifp->flags);

	return obj;
}