Exemple #1
0
/**
 * Find a first thread that can be unblocked for a given handle and signal type.
 *
 * @param handle Platform-specific handle.
 * @param signalType Enumerated signal type.
 *
 * @return JVMSPI_ThreadID Java thread id than can be unblocked
 *         0 if no matching thread can be found
 *
 */
static JVMSPI_ThreadID
jsr120_cbs_get_blocked_thread_from_handle(long handle, jint waitingFor) {
    JVMSPI_BlockedThreadInfo *blocked_threads;
    int n;
    int i;

    blocked_threads = SNI_GetBlockedThreads(&n);

    for (i = 0; i < n; i++) {
	MidpReentryData *p =
            (MidpReentryData*)(blocked_threads[i].reentry_data);
	if (p != NULL) {

	    /* wait policy: 1. threads waiting for network reads
                            2. threads waiting for network writes
         	            3. threads waiting for network push event*/
	    if ((waitingFor == WMA_CBS_READ_SIGNAL) &&
                (waitingFor == (int)p->waitingFor) &&
         	(p->descriptor == handle)) {
		return blocked_threads[i].thread_id;
            }

            if ((waitingFor == PUSH_SIGNAL) &&
                (waitingFor == (int)p->waitingFor) &&
                (findPushBlockedHandle(handle) != 0)) {
                return blocked_threads[i].thread_id;
	    }

	}

    }

    return 0;
}
int main(int argc, char **argv) {

#if ENABLE_PCSL
  pcsl_mem_initialize(NULL, 0);
#endif

  // Call this before any other Jvm_ functions.
  JVM_Initialize();

  // Ignore arg[0] -- the name of the program.
  argc --;
  argv ++;

  while (true) {
    int n = JVM_ParseOneArg(argc, argv);
    if (n < 0) {
      JVMSPI_DisplayUsage(NULL);
      return -1;
    } else if (n == 0) {
      break;
    }
    argc -= n;
    argv += n;
  }
  
  int rv;

  if (JVM_GetConfig(JVM_CONFIG_SLAVE_MODE) == KNI_FALSE) {
    // Run the VM in regular mode -- JVM_Start won't return until
    // the VM completes execution.
    rv = JVM_Start(NULL, NULL, argc, argv);
  } else {
    JVM_Start(NULL, NULL, argc, argv);

    for (;;) {
      jlong timeout = JVM_TimeSlice();
      if (timeout <= ((jlong)-2)) {
        break;
      } else {
        int blocked_threads_count;
        JVMSPI_BlockedThreadInfo * blocked_threads;

        blocked_threads = SNI_GetBlockedThreads(&blocked_threads_count);
        JVMSPI_CheckEvents(blocked_threads, blocked_threads_count, timeout);
      }
    }

    rv = JVM_CleanUp();
  }

  printf("ADSEXITCODE=%d\n", rv);

#if ENABLE_PCSL
  pcsl_mem_finalize();
#endif

  return rv;
}
/**
 * Find and unblock all Java threads based on what the thread is waiting
 * for and which descriptor it is waiting on.
 *
 * @param waitingFor used to match MidpReentryData.waitingFor
 * @param descriptor used to match MidpReentryData.descriptor
 * @param status the value stored into MidpReentryData.status for every
 *               thread that is unblocked
 */
void
midp_thread_signal(midpSignalType waitingFor, int descriptor, int status)
{
    int blocked_threads_count;
    JVMSPI_BlockedThreadInfo *blocked_threads;

    blocked_threads = SNI_GetBlockedThreads(&blocked_threads_count);

    midp_thread_signal_list(blocked_threads, blocked_threads_count,
                            waitingFor, descriptor, status);
}
Exemple #4
0
/**
 * Find the first thread that can be unblocked for a given
 * signal type
 *
 * @param signalType Enumerated signal type
 *
 * @return JVMSPI_ThreadID Java thread id than can be unblocked
 *	   0 if no matching thread can be found
 *
 */
static JVMSPI_ThreadID getBlockedThreadFromSignal(int waitingFor) {
    JVMSPI_BlockedThreadInfo *blocked_threads;
    int n;
    int i;

    blocked_threads = SNI_GetBlockedThreads(&n);

    for (i = 0; i < n; i++) {
	MidpReentryData *p =
            (MidpReentryData*)(blocked_threads[i].reentry_data);
	if (p != NULL) {

            if (waitingFor == (int)p->waitingFor) {
		return blocked_threads[i].thread_id;
            }

	}

    }

    return 0;

}
static JVMSPI_ThreadID
findBlockedHandle(int handle) {
    JVMSPI_BlockedThreadInfo *blocked_threads;
    int n;
    blocked_threads = SNI_GetBlockedThreads(&n);

    for (int i = 0; i < n; i++) {
        MidpReentryData *p =
            static_cast<MidpReentryData*>(blocked_threads[i].reentry_data);
        if (p == NULL) {
            continue;
        }

        if ((p->waitingFor == PUSH_SIGNAL) &&
            (findPushTimerBlockedHandle(handle) != 0)) {

            return blocked_threads[i].thread_id;
        }

    }

    return 0;
}
/**
 *  The function unblocks threads waiting for Transaction Store
 */
void unlock() {
    int i, n;
    JVMSPI_BlockedThreadInfo *blocked_threads;
    MidpReentryData* pThreadReentryData;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    if ((locked == KNI_TRUE) && 
            (getStorageOpenFlag(thisObject)->isOpen == KNI_TRUE)) {
        blocked_threads = SNI_GetBlockedThreads(&n);
        getStorageOpenFlag(thisObject)->isOpen = KNI_FALSE;
        locked = KNI_FALSE;
        for (i = 0; i < n; i++) {

            pThreadReentryData =
                (MidpReentryData*)(blocked_threads[i].reentry_data);

            if (pThreadReentryData == NULL) {
                continue;
            }
     
            if (pThreadReentryData->waitingFor != 
                    PAYMENT_TRANSACTION_STORE_SIGNAL) {
                continue;
            }

            pThreadReentryData->status = KNI_TRUE;
 
            midp_thread_unblock(blocked_threads[i].thread_id);
        }

    }

    KNI_EndHandles();
}
Exemple #7
0
/**
 * Scan the block thread data for every thread blocked
 * for a JSR211_SIGNAL block type with INVOKE status and unblock it.
 * For now, every blocked thread is awoken; it should 
 * check if the thread is blocked for the requested application,
 * classname.
 *
 * @param the new status of the blocked thread; either
 *  STATUS_CANCELLED or STATUS_OK
 */
static void unblockWaitingThreads(int newStatus) {
    int n;
    int i;
    JVMSPI_BlockedThreadInfo *blocked_threads = SNI_GetBlockedThreads(&n);
    const int status_mask = JSR211_INVOKE_OK | JSR211_INVOKE_CANCELLED;
    int st = newStatus==STATUS_OK ? JSR211_INVOKE_OK: JSR211_INVOKE_CANCELLED;

    for (i = 0; i < n; i++) {
        MidpReentryData *p = 
            (MidpReentryData*)(blocked_threads[i].reentry_data);
        if (p == NULL) {
            continue;
        }
        if (p->waitingFor == JSR211_SIGNAL && 
            (p->status | status_mask) != 0) {
            JVMSPI_ThreadID id = blocked_threads[i].thread_id;
    
            if (id != NULL) {
                p->status = st;
                SNI_UnblockThread(id);
            }
        }
    }
}
int main(int argc, char **argv) {
  int code = 0;

#if ENABLE_PCSL
  pcsl_mem_initialize(NULL, 0);
#endif

  // Call this before any other Jvm_ functions.
  JVM_Initialize();

  // Ignore arg[0] -- the name of the program.
  argc --;
  argv ++;

  while (true) {
    int n = JVM_ParseOneArg(argc, argv);
    if (n < 0) {
      printf("Unknown argument: %s\n", argv[0]);
      JVMSPI_DisplayUsage(NULL);
      code = -1;
      goto end;
    } else if (n == 0) {
      break;
    }
    argc -= n;
    argv += n;
  }

  if (JVM_GetConfig(JVM_CONFIG_SLAVE_MODE) == KNI_FALSE) {
    // Run the VM in regular mode -- JVM_Start won't return until
    // the VM completes execution.
    code = JVM_Start(NULL, NULL, argc, argv);
  } else {
    // Run the VM in slave mode -- we keep calling JVM_TimeSlice(),
    // which executes bytecodes for a small amount and returns. This
    // mode is necessary for platforms that need to keep the main
    // control loop outside of of the VM.
    //
    // Note that this mode is not necessary on Win32. We do it here
    // just as a demo.

    JVM_Start(NULL, NULL, argc, argv);

    for (;;) {
      jlong timeout = JVM_TimeSlice();
      if (timeout <= -2) {
        break;
      } else {
        int blocked_threads_count;
        JVMSPI_BlockedThreadInfo * blocked_threads;

        blocked_threads = SNI_GetBlockedThreads(&blocked_threads_count);
        JVMSPI_CheckEvents(blocked_threads, blocked_threads_count, timeout);
      }
    }

    code = JVM_CleanUp();
  }

end:
#if ENABLE_PCSL
  pcsl_mem_finalize();
#endif

  return code;
}