コード例 #1
0
ファイル: thread.cpp プロジェクト: duyanning/ropevm
void *threadStart(void *arg) {
    Thread *thread = (Thread *)arg;
    //Object *jThread = thread->ee->thread;
    Object *jThread = thread->thread;

    /* Parent thread created thread with suspension disabled.
       This is inherited so we need to enable */
    enableSuspend(thread);

    /* Complete initialisation of the thread structure, create the thread
       stack and add the thread to the thread list */
    initThread(thread, INST_DATA(jThread)[daemon_offset], &thread);

    /* Add thread to thread ID map hash table. */
    addThreadToHash(thread);

    /* Execute the thread's run method */
    DummyFrame dummy;
    executeMethod(&dummy, jThread, CLASS_CB(jThread->classobj)->method_table[run_mtbl_idx]);

    /* Run has completed.  Detach the thread from the VM and exit */
    detachThread(thread);

    TRACE("Thread 0x%x id: %d exited\n", thread, thread->id);
    return NULL;
}
コード例 #2
0
ファイル: thread.cpp プロジェクト: duyanning/ropevm
Object *initJavaThread(Thread *thread, char is_daemon, const char *name) {
    Object *vmthread, *jlthread, *thread_name = NULL;

    /* Create the java.lang.Thread object and the VMThread */
    if((vmthread = allocObject(vmthread_class)) == NULL ||
       (jlthread = allocObject(thread_class)) == NULL)
        return NULL;

    //thread->ee->thread = jlthread;
    thread->thread = jlthread;
    INST_DATA(vmthread)[vmData_offset] = (uintptr_t)thread;
    INST_DATA(vmthread)[thread_offset] = (uintptr_t)jlthread;

    /* Create the string for the thread name.  If null is specified
       the initialiser method will generate a name of the form Thread-X */
    if(name != NULL && (thread_name = Cstr2String(name)) == NULL)
        return NULL;

    /* Call the initialiser method -- this is for use by threads
       created or attached by the VM "outside" of Java */
    DummyFrame dummy;
    executeMethod(&dummy, jlthread, init_mb, vmthread, thread_name, NORM_PRIORITY, is_daemon);

    /* Add thread to thread ID map hash table. */
    addThreadToHash(thread);

    return jlthread;
}
コード例 #3
0
ファイル: Threading.cpp プロジェクト: acpaluri/591_Comet
static void* thread_attach(void* args) {
  char nameBuf[32];
  u4 tid = (u4)args;
  sprintf(nameBuf, "off-%d", tid);

  /* Indicate the threadId to the attaching thread.  The real thread struct will
   * be overwritten in dvmAttachCurrentThread. */
  Thread pself;
  memset(&pself, 0, sizeof(pself));
  pself.threadId = tid;
  pthread_setspecific(gDvm.pthreadKeySelf, &pself);

  JavaVMAttachArgs jniArgs;
  jniArgs.version = JNI_VERSION_1_2;
  jniArgs.name = nameBuf;
//TODO: Fix this!  Need to encode as jobject.
  jniArgs.group = (jobject)dvmGetSystemThreadGroup();

  ALOGI("ATTACHING THREAD %d", tid);
  dvmAttachCurrentThread(&jniArgs, (tid & 1 ? true : false));

  Thread* self = dvmThreadSelf();
  self->offLocal = false;
  self->offLocalOnly = false;
  addThreadToHash(self);

  // Signal the thread that created us to continue on.
  pthread_mutex_lock(&gDvm.offThreadLock);
  pthread_cond_broadcast(&gDvm.offThreadCreateCond);
  pthread_mutex_unlock(&gDvm.offThreadLock);

  void* result = thread_daemon(self);

  ALOGI("DETACHING THREAD %d", tid);

  /* Detaching will cause a sync-pull... this probably doesn't work as intended
   * still if the server creates threads. */
  bool entered = offRecoveryEnterHazard(self);
  dvmDetachCurrentThread();
  if(entered) offRecoveryClearHazard(self);

  return result;
}
コード例 #4
0
ファイル: Threading.cpp プロジェクト: acpaluri/591_Comet
void offThreadCreatedLocal(Thread* thread) {
  if(gDvm.optimizing) return;
  addThreadToHash(thread);
}