Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h
(added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h
Wed Aug 23 09:48:41 2006
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "jvmti_types.h"
+#include "apr_thread_proc.h"
+#include "open/hycomp.h"
+#include "open/jthread.h"
+
+// Tested Thread Phases
+#define TT_PHASE_NONE 0
+#define TT_PHASE_DEAD 1
+#define TT_PHASE_OK 2
+#define TT_PHASE_ERROR 3
+#define TT_PHASE_SLEEPING 4
+#define TT_PHASE_WAITING 5
+#define TT_PHASE_IN_CRITICAL_SECTON 7
+#define TT_PHASE_WAITING_ON_MONITOR 8
+#define TT_PHASE_WAITING_ON_WAIT 9
+#define TT_PHASE_WAITING_ON_JOIN 10
+#define TT_PHASE_RUNNING 11
+#define TT_PHASE_PARKED 12
+#define TT_PHASE_ATTACHED 13
+#define TT_PHASE_ATTACHED_TWICE 14
+#define TT_PHASE_STEP_1 15
+#define TT_PHASE_DETACHED 16
+#define TT_PHASE_INTERRUPTED 17
+#define TT_PHASE_ANY 18
+
+#define TTS_INIT_COMMON_MONITOR 0
+#define TTS_INIT_DIFFERENT_MONITORS 1
+
+#define MAX_TESTED_THREAD_NUMBER 5
+#define MAX_CLICKS_TO_WAIT 30
+#define CLICK_TIME_MSEC 10
+#define MAX_OWNED_MONITORS_NMB 2
+#define SLEEP_MSEC 10
+
+typedef void (*run_method_t)(void);
+
+typedef struct _jjobject{
+ void *data;
+ jboolean daemon;
+ char *name;
+ int lockword;
+ run_method_t run_method;
+}_jjobject;
+
+typedef struct _jobject{
+ _jjobject *object;
+}_jobject;
+
+typedef struct {
+ int my_index;
+ jthread java_thread;
+ jobject monitor;
+ jrawMonitorID raw_monitor;
+ JNIEnv *jni_env;
+ void * jvmti_start_proc_arg;
+ int clicks;
+ int phase;
+ int stop;
+ jint peak_count;
+ jthread_threadattr_t attrs;
+ jclass excn;
+}tested_thread_sturct_t;
+
+extern tested_thread_sturct_t *current_thread_tts;
+extern tested_thread_sturct_t *dummy_tts;
+void jni_init();
+VMEXPORT void *vm_jthread_get_tm_data(jthread thread);
+void sleep_a_click(void);
+void test_java_thread_setup(void);
+void test_java_thread_teardown(void);
+void tested_threads_init(int mode);
+void tested_threads_run(run_method_t run_method_param);
+void tested_threads_run_common(run_method_t run_method_param);
+void tested_threads_run_with_different_monitors(run_method_t run_method_param);
+void tested_threads_run_with_jvmti_start_proc(jvmtiStartFunction jvmti_start_proc);
+void tested_os_threads_run(apr_thread_start_t run_method_param);
+int tested_threads_destroy();
+int tested_threads_stop();
+tested_thread_sturct_t *get_tts(int tts_index);
+int next_tested_thread(tested_thread_sturct_t **tts);
+int prev_tested_thread(tested_thread_sturct_t **tts);
+void reset_tested_thread_iterator(tested_thread_sturct_t ** tts);
+int check_tested_thread_structures(tested_thread_sturct_t *tts);
+int check_tested_thread_phase(tested_thread_sturct_t *tts, int phase);
+int tested_thread_is_running(tested_thread_sturct_t *tts);
+int compare_threads(jthread *threads, int thread_nmb, int compare_from_end);
+int compare_pointer_sets(void ** set_a, void ** set_b, int nmb);
+int check_exception(jobject excn);
+jobject new_jobject();
+void delete_jobject(jobject obj);
+void set_phase(tested_thread_sturct_t *tts, int phase);
+void default_run_for_test(void);
+JNIEnv * new_JNIEnv();
Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_vm_emulator.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_vm_emulator.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_vm_emulator.c
(added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_vm_emulator.c
Wed Aug 23 09:48:41 2006
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "testframe.h"
+#include "thread_unit_test_utils.h"
+#include <assert.h>
+#include <apr-1/apr_pools.h>
+#include <open/hythread.h>
+#include <open/hythread_ext.h>
+#include <open/thread_externals.h>
+#include "thread_private.h"
+
+/*
+ * VM emulator for thread manager unit tests
+ */
+
+int vm_objects_are_equal(jobject obj1, jobject obj2);
+
+jmethodID isDaemonID = (jmethodID)&isDaemonID;
+jmethodID runID = (jmethodID)&runID;
+jmethodID setDaemonID = (jmethodID)&setDaemonID;
+struct JNINativeInterface_ jni_vtable;
+JNIEnv common_env = & jni_vtable;
+apr_pool_t *pool = NULL;
+
+jthread new_jobject(){
+
+ apr_status_t status;
+ _jobject *obj;
+ _jjobject *object;
+
+ if (!pool){
+ status = apr_pool_create(&pool, NULL);
+ if (status) return NULL;
+ }
+
+ obj = apr_palloc(pool, sizeof(_jobject));
+ object = apr_palloc(pool, sizeof(_jjobject));
+ assert(obj);
+ obj->object = object;
+ obj->object->data = NULL;
+ obj->object->daemon = 0;
+ obj->object->name = NULL;
+ return obj;
+}
+
+void delete_jobject(jobject obj){
+
+}
+
+JNIEnv * new_JNIEnv(){
+ return &common_env;
+}
+
+void delete_JNIEnv(JNIEnv *env){
+}
+
+jclass JNICALL FindClass(JNIEnv *env, const char *name){
+ return new_jobject();
+}
+
+jmethodID JNICALL GetMethodID(JNIEnv *env, jclass clazz,
+ const char *name, const char *sig){
+ if (! strcmp(name, "isDaemon")){
+ return isDaemonID;
+ } else if (! strcmp(name, "setDaemon")){
+ return setDaemonID;
+ } else if (! strcmp(name, "runImpl")){
+ return runID;
+ }
+ log_info("GetMethodID emulator: UNKNOWN METHOD");
+ assert(0);
+ return 0;
+}
+
+jboolean JNICALL CallBooleanMethodA(JNIEnv *env, jobject obj,
+ jmethodID methodID, jvalue * args){
+ if (methodID == isDaemonID){
+ return obj->object->daemon;
+ }
+ log_info("CallBooleanMethodA emulator: UNKNOWN METHOD");
+ assert(0);
+ return 0;
+}
+
+//void JNICALL CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...){
+//
+// printf("CallVoidMethod...\n");
+//}
+//
+void JNICALL CallVoidMethodA(JNIEnv *env, jobject obj,
+ jmethodID methodID, jvalue * args){
+
+ if (methodID == setDaemonID){
+ obj->object->daemon = args[0].z;
+ } else if (methodID == runID){
+ obj->object->run_method();
+ } else {
+ log_info("CallVoidMethodA emulator: UNKNOWN METHOD");
+ assert(0);
+ }
+}
+
+const char* JNICALL GetStringUTFChars(JNIEnv *env, jstring str, jboolean *isCopy){
+ return str->object->name;
+}
+
+jstring JNICALL NewStringUTF(JNIEnv *env, const char * name){
+
+ jstring jname = new_jobject();
+ jname->object->name = (char *)name;
+ return jname;
+}
+
+jobject JNICALL NewGlobalRef(JNIEnv *env, jobject object){
+ jobject obj = new_jobject();
+ assert(obj);
+ assert(object);
+ obj->object = object->object;
+ return obj;
+}
+
+void JNICALL DeleteGlobalRef(JNIEnv *env, jobject object){
+}
+
+void JNICALL ReleaseStringUTFChars(JNIEnv *env, jstring str, const char* chars){
+}
+
+jint JNICALL ThrowNew (JNIEnv *env, jclass clazz, const char* chars){
+ tested_thread_sturct_t * tts;
+ hythread_t tm_native_thread;
+ jvmti_thread_t tm_java_thread;
+
+ tm_native_thread = hythread_self();
+ tm_java_thread = hythread_get_private_data(tm_native_thread);
+
+ reset_tested_thread_iterator(&tts);
+ while(next_tested_thread(&tts)){
+ if (vm_objects_are_equal(tts->java_thread, tm_java_thread->thread_object)){
+ tts->excn = clazz;
+ return 0;
+ }
+ }
+ return 1;
+}
+
+jint JNICALL Throw (JNIEnv *env, jobject clazz){
+ tested_thread_sturct_t * tts;
+ hythread_t tm_native_thread;
+ jvmti_thread_t tm_java_thread;
+
+ tm_native_thread = hythread_self();
+ tm_java_thread = hythread_get_private_data(tm_native_thread);
+
+ reset_tested_thread_iterator(&tts);
+ while(next_tested_thread(&tts)){
+ if (vm_objects_are_equal(tts->java_thread, tm_java_thread->thread_object)){
+ tts->excn = clazz;
+ return 0;
+ }
+ }
+ return 1;
+}
+
+
+void jni_init(){
+
+ jni_vtable.FindClass = &FindClass;
+ jni_vtable.GetMethodID = &GetMethodID;
+ jni_vtable.CallBooleanMethodA = &CallBooleanMethodA;
+ //jni_vtable.CallVoidMethod = &CallVoidMethod;
+ jni_vtable.CallVoidMethodA = &CallVoidMethodA;
+ jni_vtable.GetStringUTFChars = &GetStringUTFChars;
+ jni_vtable.NewStringUTF = &NewStringUTF;
+ jni_vtable.DeleteGlobalRef = &DeleteGlobalRef;
+ jni_vtable.NewGlobalRef = &NewGlobalRef;
+ jni_vtable.ReleaseStringUTFChars = &ReleaseStringUTFChars;
+ jni_vtable.ThrowNew = ThrowNew;
+ jni_vtable.Throw = Throw;
+}
+
Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_vm_emulator.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/tm2vm.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/tm2vm.c?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/tm2vm.c (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/tm2vm.c Wed Aug 23 09:48:41
2006
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Artem Aliev
+ * @version $Revision$
+ */
+
+#include "thread_private.h"
+#include <open/hythread_ext.h>
+#include "open/thread_externals.h"
+#include "thread_unit_test_utils.h"
+
+/**
+ * This file contains the functions which eventually should become part of vmcore.
+ * This localizes the dependencies of Thread Manager on vmcore component.
+ */
+
+void *vm_object_get_lockword_addr(jobject monitor){
+ //return (*(ManagedObject**)monitor)->get_obj_info_addr();
+ return (void *)&monitor->object->lockword;
+}
+
+void* vm_jthread_get_tm_data(jthread thread)
+{
+ /*
+ JNIEnv *jenv = (JNIEnv*)jni_native_intf;
+ jclass jThreadClass = jenv->GetObjectClass(thread);
+ jfieldID field_id = jenv->GetFieldID(jThreadClass, "vm_thread", "J");
+ POINTER_SIZE_INT data = (POINTER_SIZE_INT)jenv->GetLongField(thread, field_id);
+
+ return (void *)data;
+ */
+ return thread->object->data;
+}
+
+void vm_jthread_set_tm_data(jthread jt, void* nt) {
+ /*
+ JNIEnv *jenv = (JNIEnv*)jni_native_intf;
+ jclass jthreadclass = jenv->GetObjectClass(jt);
+ jfieldID field_id = jenv->GetFieldID(jthreadclass, "vm_thread", "J");
+ jenv->SetLongField(jt, field_id, (jlong)(POINTER_SIZE_INT)nt);
+ */
+ jt->object->data = nt;
+}
+
+IDATA jthread_throw_exception(char* name, char* message) {
+ return 0;
+}
+
+int vm_objects_are_equal(jobject obj1, jobject obj2){
+ //ObjectHandle h1 = (ObjectHandle)obj1;
+ //ObjectHandle h2 = (ObjectHandle)obj2;
+ if (obj1 == NULL && obj2 == NULL){
+ return 1;
+ }
+ if (obj1 == NULL || obj2 == NULL){
+ return 0;
+ }
+ return obj1->object == obj2->object;
+}
+
+void * vm_get_object(jobject obj){
+ if (obj == NULL){
+ return NULL;
+ }
+ return obj->object;
+}
+
+
+int ti_is_enabled(){
+ return 1;
+}
+//--------------------------------------------------------------------------------
+
+int vm_attach() {
+ return 0;
+}
+int vm_detach() {
+ return 0;
+}
+void jvmti_send_thread_start_end_event(int is_start) {
+ //is_start ? process_jvmti_event(JVMTI_EVENT_THREAD_START, 0, 0)
+ // :process_jvmti_event(JVMTI_EVENT_THREAD_END, 1, 0);
+}
+void jvmti_send_wait_monitor_event(jobject monitor, jlong timeout) {
+ hythread_t tm_native_thread = hythread_self();
+ //TRACE2("jvmti.monitor.wait", "Monitor wait event, monitor = " << monitor);
+ tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE;
+ tm_native_thread->state |= TM_THREAD_STATE_WAITING | TM_THREAD_STATE_IN_MONITOR_WAIT;
+ tm_native_thread->state |= timeout ? TM_THREAD_STATE_WAITING_WITH_TIMEOUT :
+ TM_THREAD_STATE_WAITING_INDEFINITELY;
+ //process_jvmti_event(JVMTI_EVENT_MONITOR_WAIT, 1, monitor, timeout);
+}
+void jvmti_send_waited_monitor_event(jobject monitor, jboolean is_timed_out) {
+ hythread_t tm_native_thread = hythread_self();
+ //TRACE2("jvmti.monitor.waited", "Monitor wait event, monitor = " << monitor);
+ tm_native_thread->state &= ~(TM_THREAD_STATE_WAITING | TM_THREAD_STATE_IN_MONITOR_WAIT
|
+ TM_THREAD_STATE_WAITING_INDEFINITELY |
+ TM_THREAD_STATE_WAITING_WITH_TIMEOUT);
+ tm_native_thread->state |= TM_THREAD_STATE_RUNNABLE;
+ //process_jvmti_event(JVMTI_EVENT_MONITOR_WAITED, 1, monitor, is_timed_out);
+}
+void jvmti_send_contended_enter_or_entered_monitor_event(jobject monitor, int isEnter) {
+ hythread_t tm_native_thread = hythread_self();
+ //TRACE2("jvmti.monitor.enter", "Monitor enter event, monitor = " << monitor <<
" is enter= " << isEnter);
+ if(isEnter){
+ tm_native_thread->state |= TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+ tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE;
+ //process_jvmti_event(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, 1, monitor);
+ } else {
+ tm_native_thread->state &= ~TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+ tm_native_thread->state |= TM_THREAD_STATE_RUNNABLE;
+ //process_jvmti_event(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, 1, monitor);
+ }
+}
Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/tm2vm.c
------------------------------------------------------------------------------
svn:eol-style = native
|