harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r597138 [6/15] - in /harmony/enhanced/drlvm/trunk: build/make/ build/make/components/vm/ vm/include/ vm/include/open/ vm/jitrino/src/codegenerator/ia32/ vm/port/src/encoder/ia32_em64t/ vm/port/src/lil/ia32/pim/ vm/tests/ncai/ vm/tests/ncai/...
Date Wed, 21 Nov 2007 16:29:54 GMT
Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace05n/GetStackTrace05n.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace05n/GetStackTrace05n.cpp?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace05n/GetStackTrace05n.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace05n/GetStackTrace05n.cpp Wed Nov 21 08:29:40 2007
@@ -0,0 +1,448 @@
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+
+/* *********************************************************************** */
+
+#include "events.h"
+#include "utils.h"
+#include "ncai.h"
+
+#ifdef POSIX
+#include <stdlib.h>
+#include <time.h>
+#else
+#include <windows.h>
+#include <CRTDBG.H>
+#endif
+
+#ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  { timespec delay = {(_x_)/1000, 1000000*((_x_)%1000)}; nanosleep(&delay, NULL); }
+#else // #ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  Sleep((_x_))
+#endif // #ifdef POSIX
+
+static int g_stop_thread = 0;
+static int g_resume_agent_thread = 0;
+static jthread g_thread_jthread;
+//static jthread g_agent_thread;
+
+static volatile int no_opt = 1; //used to prevent inlining;
+
+static bool test = false;
+static bool util = false;
+static bool flag = false;
+
+const char test_case_name[] = "GetStackTrace05n";
+
+static void Test1(JNIEnv *env, jobject obj);
+static void Test2(JNIEnv *env, jobject obj);
+static void Test3(JNIEnv *env, jobject obj);
+//static void JNICALL test_function(jvmtiEnv*, JNIEnv*, void*);
+static  bool CheckFrames(ncaiEnv*, ncaiThread, ncaiFrameInfo**, jint*);
+
+extern "C" JNIEXPORT void JNICALL
+Java_ncai_funcs_GetStackTrace05n_resumeagent(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    g_resume_agent_thread = 1;
+}
+
+extern "C" JNIEXPORT jboolean JNICALL
+Java_ncai_funcs_GetStackTrace05n_stopsignal(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    return g_stop_thread ? true : false;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetStackTrace05n_TestFunction
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction\n");
+
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetMethodID(clazz, "test_java_func2", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetStaticMethodID for 'test_java_func2' failed\n");
+        return;
+    }
+    env->CallVoidMethod(obj, mid);
+    return;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetStackTrace05n_TestFunction1
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction1\n");
+    Test1(env, obj);
+
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetStaticMethodID(clazz, "sleep", "(J)V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetStaticMethodID for 'sleep' failed\n");
+        return;
+    }
+
+    g_resume_agent_thread = 1;/*
+    while(g_stop_thread)
+    {
+        fprintf(stderr, "thread... \n");
+        SLEEP_UNIVERSAL(100);
+//        env->CallStaticVoidMethod(clazz, mid, 500);
+    }*/
+
+    return;
+}
+
+void JNICALL ThreadStart(jvmtiEnv *jvmti_env,
+            JNIEnv* jni_env,
+            jthread thread)
+{
+    jvmtiPhase phase;
+    jvmtiError result;
+    jvmtiThreadInfo tinfo;
+
+    result = jvmti_env->GetPhase(&phase);
+    if (result != JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE)
+        return;
+
+    result = jvmti_env->GetThreadInfo(thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+        return;
+
+    if (strcmp(tinfo.name, "java_thread") != 0)
+        return;
+
+    printf("ThreadStart: java_thread\n");
+    g_thread_jthread = jni_env->NewGlobalRef(thread);
+/*
+    jclass clazz = jni_env->FindClass("java/lang/Thread");
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: JNI: FindClass failed\n");
+        return;
+    }
+
+    jmethodID mid = jni_env->GetMethodID(clazz, "<init>", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: JNI: GetMethodID failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewObject(clazz, mid, "native_agent_thread");
+    if (!g_agent_thread)
+    {
+        fprintf(stderr, "\tnative: JNI: NewObject failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewGlobalRef(g_agent_thread);
+    result = jvmti_env->GetThreadInfo(g_agent_thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: JNI: GetThreadInfo failed\n");
+    }
+
+    result = jvmti_env->RunAgentThread(g_agent_thread, test_function, NULL, JVMTI_THREAD_NORM_PRIORITY);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: jvmti: RunAgentThread failed\n");
+        return;
+    }*/
+}
+/*
+JNIEXPORT jint
+JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
+{
+    jint res;
+    jvmtiEnv* jvmti_env = NULL;
+
+    res = jvm->GetEnv((void**)&jvmti_env, JVMTI_VERSION_1_0);
+    if (res != JNI_OK || jvmti_env == NULL)
+        return JNI_ERR;
+
+    jvmtiEventCallbacks callbacks;
+    callbacks.ThreadStart=&ThreadStart;
+
+    jvmti_env->SetEventCallbacks(&callbacks, sizeof(callbacks));
+    jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL);
+
+    return JNI_OK;
+}
+*/
+/* *********************************************************************** */
+
+JNIEXPORT jint JNICALL Agent_OnLoad(prms_AGENT_ONLOAD)
+{
+
+    Callbacks CB;
+    CB.cbThreadStart = &ThreadStart;
+    check_AGENT_ONLOAD;
+    jvmtiEvent events[] = { JVMTI_EVENT_EXCEPTION, JVMTI_EVENT_THREAD_START, JVMTI_EVENT_VM_DEATH };
+    cb_exc;
+    cb_death;
+    return func_for_Agent_OnLoad(vm, options, reserved, &CB,
+        events, sizeof(events)/sizeof(jvmtiEvent), test_case_name, DEBUG_OUT);
+}
+
+/* *********************************************************************** */
+
+void JNICALL callbackException(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+                               jthread thread, jmethodID method,
+                               jlocation location, jobject exception,
+                               jmethodID catch_method, jlocation catch_location)
+{
+    check_EXCPT;
+    if (flag) return;
+
+    /*
+     * Function separate all other exceptions in all other method
+     */
+    if (!check_phase_and_method_debug(jvmti_env, method, SPP_LIVE_ONLY,
+                "special_method", DEBUG_OUT)) return;
+
+    flag = true;
+    util = true;
+
+    fprintf(stderr, "agent... \n");
+    SLEEP_UNIVERSAL(300);
+    ////////////////////ncai env get
+    jvmtiError err;
+    ncaiError ncai_err;
+
+    jvmtiExtensionFunctionInfo* ext_info = NULL;
+    jint ext_count = 0;
+
+    err = jvmti_env->GetExtensionFunctions(&ext_count, &ext_info);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (ext_count == 0 || ext_info == NULL)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned no extensions\n");
+        test = false;
+        return;
+    }
+
+    jvmtiExtensionFunction get_ncai_func = NULL;
+
+    fprintf(stderr, "agent... \n");
+    for (int k = 0; k < ext_count; k++)
+    {
+        if (strcmp(ext_info[k].id, "org.apache.harmony.vm.GetExtensionEnv") == 0)
+        {
+            get_ncai_func = ext_info[k].func;
+            break;
+        }
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (get_ncai_func == NULL)
+    {
+        fprintf(stderr, "test_function: GetNCAIEnvironment() nas not been found among JVMTI extensions\n");
+        test = false;
+        return;
+    }
+
+    ncaiEnv* ncai_env = NULL;
+
+    fprintf(stderr, "agent... \n");
+    err = get_ncai_func(jvmti_env, &ncai_env, NCAI_VERSION_1_0);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    if (ncai_env == NULL)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned NULL environment\n");
+        test = false;
+        return;
+    }
+    fprintf(stderr, "agent... \n");
+    ///////////////////////////////////
+    ncaiThread ncai_thread;
+
+    fprintf(stderr, "calling ncai->GetThreadHandle()...\n");
+    ncai_err = ncai_env->GetThreadHandle(g_thread_jthread, &ncai_thread);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->GetThreadHandle() returned error: %d", ncai_err);
+        test = false;
+        return;
+    }
+
+    ncaiFrameInfo* frames;
+    jint frames_returned;
+
+    while(!g_resume_agent_thread)
+            SLEEP_UNIVERSAL(200);
+
+    g_resume_agent_thread = 0;
+
+    test = CheckFrames(ncai_env, ncai_thread, &frames, &frames_returned);
+    g_stop_thread = 1;
+/*    SLEEP_UNIVERSAL(500);
+
+    while(!g_resume_agent_thread)
+            SLEEP_UNIVERSAL(200);
+
+    g_resume_agent_thread = 0;
+
+    g_stop_thread = 0;
+    SLEEP_UNIVERSAL(500);
+
+    while(!g_resume_agent_thread)
+            SLEEP_UNIVERSAL(200);
+
+    g_resume_agent_thread = 0;
+    g_stop_thread = 1; */
+}
+
+void JNICALL callbackVMDeath(prms_VMDEATH)
+{
+    check_VMDEATH;
+    func_for_callback_VMDeath(jni_env, jvmti_env, test_case_name, test, util);
+}
+
+/* *********************************************************************** */
+
+void Test1(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test1(env, obj);
+
+    fprintf(stderr, "thread - pure native Test1\n");
+    return Test2(env, obj);
+}
+
+void Test2(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test2(env, obj);
+
+    fprintf(stderr, "thread - pure native Test2\n");
+    return Test3(env, obj);
+}
+
+void Test3(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test3(env, obj);
+
+    fprintf(stderr, "thread - pure native Test3\n");
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetStaticMethodID(clazz, "sleep", "(J)V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetStaticMethodID for 'sleep' failed\n");
+        return;
+    }
+
+    g_resume_agent_thread = 1;
+    while(!g_stop_thread)
+    {
+        fprintf(stderr, "thread... \n");
+        SLEEP_UNIVERSAL(100);
+//        env->CallStaticVoidMethod(clazz, mid, 500);
+    }
+
+    return;
+}
+
+bool CheckFrames(ncaiEnv *ncai_env, ncaiThread ncai_thread, ncaiFrameInfo** ret_frames, jint* ret_count)
+{
+    bool ret = true;
+    //warning fix
+    int w_fix = sizeof(ret_frames);
+    w_fix += sizeof(ret_count);
+    //
+
+    fprintf(stderr, "agent... suspend thread \n");
+    ncaiError ncai_err = ncai_env->SuspendThread(ncai_thread);
+
+    do
+    {
+        if (ncai_err != NCAI_ERROR_NONE)
+        {
+            fprintf(stderr, "ncai->SuspendThread() returned error: %d,\n", ncai_err);
+            ret = false;
+            break;
+        }
+
+        jint frame_count;
+        fprintf(stderr, "calling ncai->GetFrameCount()...\n");
+        ncai_err = ncai_env->GetFrameCount(ncai_thread, &frame_count);
+        if (ncai_err != NCAI_ERROR_NONE)
+        {
+            fprintf(stderr, "ncai->GetFrameCount() returned error: %d,\n", ncai_err);
+            ret = false;
+            break;
+        }
+
+        fprintf(stderr, "test_function: frame count = %d\n", frame_count);
+
+        ncaiFrameInfo* frames = new ncaiFrameInfo[frame_count];
+        jint frames_returned;
+
+
+        fprintf(stderr, "calling ncai->GetStackTrace()...\n");
+        ncai_err = ncai_env->GetStackTrace(NULL, frame_count, frames, &frames_returned);
+        if (ncai_err != NCAI_ERROR_INVALID_THREAD)
+        {
+            ret = false;
+        }
+    } while(false);
+
+    fprintf(stderr, "agent... resuming thread \n");
+    ncai_err = ncai_env->ResumeThread(ncai_thread);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->ResumeThread() returned error: %d,\n", ncai_err);
+        ret = false;
+    }
+
+    return ret;
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace05n/GetStackTrace05n.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace05n/GetStackTrace05n.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace05n/GetStackTrace05n.java?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace05n/GetStackTrace05n.java (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace05n/GetStackTrace05n.java Wed Nov 21 08:29:40 2007
@@ -0,0 +1,90 @@
+package ncai.funcs;
+
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+public class GetStackTrace05n extends Thread{
+    public native void TestFunction();
+    public native void TestFunction1();
+    public static native boolean stopsignal();
+    public static native void resumeagent();
+
+    static boolean NoLibrary = false;
+    static {
+        try{
+            System.loadLibrary("GetStackTrace05n");
+        }
+        catch(Throwable e){
+            NoLibrary = true;
+        }
+    }
+
+    GetStackTrace05n(String name)
+    {
+        super(name);
+    }
+
+    static public void main(String args[]) {
+        if(NoLibrary) return;
+        new GetStackTrace05n("java_thread").start();
+        special_method();
+        /*
+        while(!stopsignal()){
+            try {
+                sleep(100, 0); // milliseconds
+            } catch (java.lang.InterruptedException ie) {}
+            System.out.println("\tJAVA: main: ...");
+        }
+
+        try {
+            sleep(1000, 0); // milliseconds
+        } catch (java.lang.InterruptedException ie) {}
+
+        System.out.println("\tJAVA: main - exit");
+
+*/
+        return;
+    }
+
+    public void test_java_func1(){
+        System.out.println("thread - java func1\n");
+        TestFunction();
+    }
+
+    public void test_java_func2(){
+        System.out.println("thread - java func2\n");
+        test_java_func3();
+    }
+
+    public void test_java_func3(){
+        System.out.println("thread - java func3\n");
+        TestFunction1();
+        resumeagent();  /*
+        while(!stopsignal())
+        {
+            try {
+                sleep(100, 0); // milliseconds
+            } catch (java.lang.InterruptedException ie) {}
+            //System.out.println("\tJAVA: Thread: ...");
+        }*/
+    }
+
+    static public void special_method() {
+        /*
+         * Transfer control to native part.
+         */
+        try {
+            throw new InterruptedException();
+        } catch (Throwable tex) { }
+        return;
+    }
+
+    public void run() {
+        System.out.println("thread - java run\n");
+        test_java_func1();
+    }
+}
+
+

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace05n/GetStackTrace05n.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace06n/GetStackTrace06n.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace06n/GetStackTrace06n.cpp?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace06n/GetStackTrace06n.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace06n/GetStackTrace06n.cpp Wed Nov 21 08:29:40 2007
@@ -0,0 +1,446 @@
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+
+/* *********************************************************************** */
+
+#include "events.h"
+#include "utils.h"
+#include "ncai.h"
+
+#ifdef POSIX
+#include <stdlib.h>
+#include <time.h>
+#else
+#include <windows.h>
+#include <CRTDBG.H>
+#endif
+
+#ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  { timespec delay = {(_x_)/1000, 1000000*((_x_)%1000)}; nanosleep(&delay, NULL); }
+#else // #ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  Sleep((_x_))
+#endif // #ifdef POSIX
+
+static int g_stop_thread = 0;
+static int g_resume_agent_thread = 0;
+static jthread g_thread_jthread;
+//static jthread g_agent_thread;
+
+static volatile int no_opt = 1; //used to prevent inlining;
+
+static bool test = false;
+static bool util = false;
+static bool flag = false;
+
+const char test_case_name[] = "GetStackTrace06n";
+
+static void Test1(JNIEnv *env, jobject obj);
+static void Test2(JNIEnv *env, jobject obj);
+static void Test3(JNIEnv *env, jobject obj);
+//static void JNICALL test_function(jvmtiEnv*, JNIEnv*, void*);
+static  bool CheckFrames(ncaiEnv*, ncaiThread, ncaiFrameInfo**, jint*);
+
+extern "C" JNIEXPORT void JNICALL
+Java_ncai_funcs_GetStackTrace06n_resumeagent(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    g_resume_agent_thread = 1;
+}
+
+extern "C" JNIEXPORT jboolean JNICALL
+Java_ncai_funcs_GetStackTrace06n_stopsignal(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    return g_stop_thread ? true : false;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetStackTrace06n_TestFunction
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction\n");
+
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetMethodID(clazz, "test_java_func2", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetStaticMethodID for 'test_java_func2' failed\n");
+        return;
+    }
+    env->CallVoidMethod(obj, mid);
+    return;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetStackTrace06n_TestFunction1
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction1\n");
+    Test1(env, obj);
+
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetStaticMethodID(clazz, "sleep", "(J)V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetStaticMethodID for 'sleep' failed\n");
+        return;
+    }
+
+    g_resume_agent_thread = 1;/*
+    while(g_stop_thread)
+    {
+        fprintf(stderr, "thread... \n");
+        SLEEP_UNIVERSAL(100);
+//        env->CallStaticVoidMethod(clazz, mid, 500);
+    }*/
+
+    return;
+}
+
+void JNICALL ThreadStart(jvmtiEnv *jvmti_env,
+            JNIEnv* jni_env,
+            jthread thread)
+{
+    jvmtiPhase phase;
+    jvmtiError result;
+    jvmtiThreadInfo tinfo;
+
+    result = jvmti_env->GetPhase(&phase);
+    if (result != JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE)
+        return;
+
+    result = jvmti_env->GetThreadInfo(thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+        return;
+
+    if (strcmp(tinfo.name, "java_thread") != 0)
+        return;
+
+    printf("ThreadStart: java_thread\n");
+    g_thread_jthread = jni_env->NewGlobalRef(thread);
+/*
+    jclass clazz = jni_env->FindClass("java/lang/Thread");
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: JNI: FindClass failed\n");
+        return;
+    }
+
+    jmethodID mid = jni_env->GetMethodID(clazz, "<init>", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: JNI: GetMethodID failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewObject(clazz, mid, "native_agent_thread");
+    if (!g_agent_thread)
+    {
+        fprintf(stderr, "\tnative: JNI: NewObject failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewGlobalRef(g_agent_thread);
+    result = jvmti_env->GetThreadInfo(g_agent_thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: JNI: GetThreadInfo failed\n");
+    }
+
+    result = jvmti_env->RunAgentThread(g_agent_thread, test_function, NULL, JVMTI_THREAD_NORM_PRIORITY);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: jvmti: RunAgentThread failed\n");
+        return;
+    }*/
+}
+/*
+JNIEXPORT jint
+JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
+{
+    jint res;
+    jvmtiEnv* jvmti_env = NULL;
+
+    res = jvm->GetEnv((void**)&jvmti_env, JVMTI_VERSION_1_0);
+    if (res != JNI_OK || jvmti_env == NULL)
+        return JNI_ERR;
+
+    jvmtiEventCallbacks callbacks;
+    callbacks.ThreadStart=&ThreadStart;
+
+    jvmti_env->SetEventCallbacks(&callbacks, sizeof(callbacks));
+    jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL);
+
+    return JNI_OK;
+}
+*/
+/* *********************************************************************** */
+
+JNIEXPORT jint JNICALL Agent_OnLoad(prms_AGENT_ONLOAD)
+{
+
+    Callbacks CB;
+    CB.cbThreadStart = &ThreadStart;
+    check_AGENT_ONLOAD;
+    jvmtiEvent events[] = { JVMTI_EVENT_EXCEPTION, JVMTI_EVENT_THREAD_START, JVMTI_EVENT_VM_DEATH };
+    cb_exc;
+    cb_death;
+    return func_for_Agent_OnLoad(vm, options, reserved, &CB,
+        events, sizeof(events)/sizeof(jvmtiEvent), test_case_name, DEBUG_OUT);
+}
+
+/* *********************************************************************** */
+
+void JNICALL callbackException(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+                               jthread thread, jmethodID method,
+                               jlocation location, jobject exception,
+                               jmethodID catch_method, jlocation catch_location)
+{
+    check_EXCPT;
+    if (flag) return;
+
+    /*
+     * Function separate all other exceptions in all other method
+     */
+    if (!check_phase_and_method_debug(jvmti_env, method, SPP_LIVE_ONLY,
+                "special_method", DEBUG_OUT)) return;
+
+    flag = true;
+    util = true;
+
+    fprintf(stderr, "agent... \n");
+    SLEEP_UNIVERSAL(300);
+    ////////////////////ncai env get
+    jvmtiError err;
+    ncaiError ncai_err;
+
+    jvmtiExtensionFunctionInfo* ext_info = NULL;
+    jint ext_count = 0;
+
+    err = jvmti_env->GetExtensionFunctions(&ext_count, &ext_info);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (ext_count == 0 || ext_info == NULL)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned no extensions\n");
+        test = false;
+        return;
+    }
+
+    jvmtiExtensionFunction get_ncai_func = NULL;
+
+    fprintf(stderr, "agent... \n");
+    for (int k = 0; k < ext_count; k++)
+    {
+        if (strcmp(ext_info[k].id, "org.apache.harmony.vm.GetExtensionEnv") == 0)
+        {
+            get_ncai_func = ext_info[k].func;
+            break;
+        }
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (get_ncai_func == NULL)
+    {
+        fprintf(stderr, "test_function: GetNCAIEnvironment() nas not been found among JVMTI extensions\n");
+        test = false;
+        return;
+    }
+
+    ncaiEnv* ncai_env = NULL;
+
+    fprintf(stderr, "agent... \n");
+    err = get_ncai_func(jvmti_env, &ncai_env, NCAI_VERSION_1_0);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    if (ncai_env == NULL)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned NULL environment\n");
+        test = false;
+        return;
+    }
+    fprintf(stderr, "agent... \n");
+    ///////////////////////////////////
+    ncaiThread ncai_thread;
+
+    fprintf(stderr, "calling ncai->GetThreadHandle()...\n");
+    ncai_err = ncai_env->GetThreadHandle(g_thread_jthread, &ncai_thread);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->GetThreadHandle() returned error: %d", ncai_err);
+        test = false;
+        return;
+    }
+
+    ncaiFrameInfo* frames;
+    jint frames_returned;
+
+    while(!g_resume_agent_thread)
+            SLEEP_UNIVERSAL(200);
+
+    g_resume_agent_thread = 0;
+
+    test = CheckFrames(ncai_env, ncai_thread, &frames, &frames_returned);
+    g_stop_thread = 1;
+/*    SLEEP_UNIVERSAL(500);
+
+    while(!g_resume_agent_thread)
+            SLEEP_UNIVERSAL(200);
+
+    g_resume_agent_thread = 0;
+
+    g_stop_thread = 0;
+    SLEEP_UNIVERSAL(500);
+
+    while(!g_resume_agent_thread)
+            SLEEP_UNIVERSAL(200);
+
+    g_resume_agent_thread = 0;
+    g_stop_thread = 1; */
+}
+
+void JNICALL callbackVMDeath(prms_VMDEATH)
+{
+    check_VMDEATH;
+    func_for_callback_VMDeath(jni_env, jvmti_env, test_case_name, test, util);
+}
+
+/* *********************************************************************** */
+
+void Test1(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test1(env, obj);
+
+    fprintf(stderr, "thread - pure native Test1\n");
+    return Test2(env, obj);
+}
+
+void Test2(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test2(env, obj);
+
+    fprintf(stderr, "thread - pure native Test2\n");
+    return Test3(env, obj);
+}
+
+void Test3(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test3(env, obj);
+
+    fprintf(stderr, "thread - pure native Test3\n");
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetStaticMethodID(clazz, "sleep", "(J)V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetStaticMethodID for 'sleep' failed\n");
+        return;
+    }
+
+    g_resume_agent_thread = 1;
+    while(!g_stop_thread)
+    {
+        fprintf(stderr, "thread... \n");
+        SLEEP_UNIVERSAL(100);
+//        env->CallStaticVoidMethod(clazz, mid, 500);
+    }
+
+    return;
+}
+
+bool CheckFrames(ncaiEnv *ncai_env, ncaiThread ncai_thread, ncaiFrameInfo** ret_frames, jint* ret_count)
+{
+    bool ret = true;
+    //warning fix
+    int w_fix = sizeof(ret_frames);
+    w_fix += sizeof(ret_count);
+    //
+
+    fprintf(stderr, "agent... suspend thread \n");
+    ncaiError ncai_err = ncai_env->SuspendThread(ncai_thread);
+
+    do
+    {
+        if (ncai_err != NCAI_ERROR_NONE)
+        {
+            fprintf(stderr, "ncai->SuspendThread() returned error: %d,\n", ncai_err);
+            ret = false;
+            break;
+        }
+
+        jint frame_count;
+        fprintf(stderr, "calling ncai->GetFrameCount()...\n");
+        ncai_err = ncai_env->GetFrameCount(ncai_thread, &frame_count);
+        if (ncai_err != NCAI_ERROR_NONE)
+        {
+            fprintf(stderr, "ncai->GetFrameCount() returned error: %d,\n", ncai_err);
+            ret = false;
+            break;
+        }
+
+        fprintf(stderr, "test_function: frame count = %d\n", frame_count);
+        ncaiFrameInfo* frames = new ncaiFrameInfo[frame_count];
+        jint frames_returned;
+
+        fprintf(stderr, "calling ncai->GetStackTrace()...\n");
+        ncai_err = ncai_env->GetStackTrace(ncai_thread, -1, frames, &frames_returned);
+        if (ncai_err != NCAI_ERROR_ILLEGAL_ARGUMENT)
+        {
+            ret = false;
+        }
+    } while(false);
+
+    fprintf(stderr, "agent... resuming thread \n");
+    ncai_err = ncai_env->ResumeThread(ncai_thread);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->ResumeThread() returned error: %d,\n", ncai_err);
+        ret = false;
+    }
+
+    return ret;
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace06n/GetStackTrace06n.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace06n/GetStackTrace06n.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace06n/GetStackTrace06n.java?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace06n/GetStackTrace06n.java (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace06n/GetStackTrace06n.java Wed Nov 21 08:29:40 2007
@@ -0,0 +1,90 @@
+package ncai.funcs;
+
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+public class GetStackTrace06n extends Thread{
+    public native void TestFunction();
+    public native void TestFunction1();
+    public static native boolean stopsignal();
+    public static native void resumeagent();
+
+    static boolean NoLibrary = false;
+    static {
+        try{
+            System.loadLibrary("GetStackTrace06n");
+        }
+        catch(Throwable e){
+            NoLibrary = true;
+        }
+    }
+
+    GetStackTrace06n(String name)
+    {
+        super(name);
+    }
+
+    static public void main(String args[]) {
+        if(NoLibrary) return;
+        new GetStackTrace06n("java_thread").start();
+        special_method();
+        /*
+        while(!stopsignal()){
+            try {
+                sleep(100, 0); // milliseconds
+            } catch (java.lang.InterruptedException ie) {}
+            System.out.println("\tJAVA: main: ...");
+        }
+
+        try {
+            sleep(1000, 0); // milliseconds
+        } catch (java.lang.InterruptedException ie) {}
+
+        System.out.println("\tJAVA: main - exit");
+
+*/
+        return;
+    }
+
+    public void test_java_func1(){
+        System.out.println("thread - java func1\n");
+        TestFunction();
+    }
+
+    public void test_java_func2(){
+        System.out.println("thread - java func2\n");
+        test_java_func3();
+    }
+
+    public void test_java_func3(){
+        System.out.println("thread - java func3\n");
+        TestFunction1();
+        resumeagent();  /*
+        while(!stopsignal())
+        {
+            try {
+                sleep(100, 0); // milliseconds
+            } catch (java.lang.InterruptedException ie) {}
+            //System.out.println("\tJAVA: Thread: ...");
+        }*/
+    }
+
+    static public void special_method() {
+        /*
+         * Transfer control to native part.
+         */
+        try {
+            throw new InterruptedException();
+        } catch (Throwable tex) { }
+        return;
+    }
+
+    public void run() {
+        System.out.println("thread - java run\n");
+        test_java_func1();
+    }
+}
+
+

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetStackTrace/GetStackTrace06n/GetStackTrace06n.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01/GetThreadHandle01.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01/GetThreadHandle01.cpp?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01/GetThreadHandle01.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01/GetThreadHandle01.cpp Wed Nov 21 08:29:40 2007
@@ -0,0 +1,393 @@
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+
+/* *********************************************************************** */
+
+#include "events.h"
+#include "utils.h"
+#include "ncai.h"
+
+#ifdef POSIX
+#include <stdlib.h>
+#include <time.h>
+#else
+#include <windows.h>
+#include <CRTDBG.H>
+#endif
+
+#ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  { timespec delay = {(_x_)/1000, 1000000*((_x_)%1000)}; nanosleep(&delay, NULL); }
+#else // #ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  Sleep((_x_))
+#endif // #ifdef POSIX
+
+static int g_stop_thread = 0;
+static volatile int g_resume_agent_thread = 0;
+static jthread g_thread_jthread;
+//static jthread g_agent_thread;
+
+static volatile int no_opt = 1; //used to prevent inlining;
+
+//static int counter = 0;
+
+static bool test = false;
+static bool util = false;
+static bool flag = false;
+
+static const char test_case_name[] = "GetThreadHandle01";
+
+static void Test1(JNIEnv *env, jobject obj);
+static void Test2(JNIEnv *env, jobject obj);
+static void Test3(JNIEnv *env, jobject obj);
+//static void JNICALL test_function(jvmtiEnv*, JNIEnv*, void*);
+//static bool CheckSuspend(ncaiEnv*, ncaiThread);
+
+extern "C" JNIEXPORT void JNICALL
+Java_ncai_funcs_GetThreadHandle01_resumeagent(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    g_resume_agent_thread = 1;
+}
+
+extern "C" JNIEXPORT jboolean JNICALL
+Java_ncai_funcs_GetThreadHandle01_stopsignal(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    return g_stop_thread ? true : false;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetThreadHandle01_TestFunction
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction\n");
+
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetMethodID(clazz, "test_java_func2", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetStaticMethodID for 'test_java_func2' failed\n");
+        return;
+    }
+    env->CallVoidMethod(obj, mid);
+    return;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetThreadHandle01_TestFunction1
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction1\n");
+    Test1(env, obj);
+    return;
+}
+
+void JNICALL ThreadStart(jvmtiEnv *jvmti_env,
+            JNIEnv* jni_env,
+            jthread thread)
+{
+    jvmtiPhase phase;
+    jvmtiError result;
+    jvmtiThreadInfo tinfo;
+
+    result = jvmti_env->GetPhase(&phase);
+    if (result != JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE)
+        return;
+
+    result = jvmti_env->GetThreadInfo(thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+        return;
+
+    if (strcmp(tinfo.name, "java_thread") != 0)
+        return;
+
+    printf("ThreadStart: java_thread\n");
+    g_thread_jthread = jni_env->NewGlobalRef(thread);
+/*
+    jclass clazz = jni_env->FindClass("java/lang/Thread");
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: JNI: FindClass failed\n");
+        return;
+    }
+
+    jmethodID mid = jni_env->GetMethodID(clazz, "<init>", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: JNI: GetMethodID failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewObject(clazz, mid, "native_agent_thread");
+    if (!g_agent_thread)
+    {
+        fprintf(stderr, "\tnative: JNI: NewObject failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewGlobalRef(g_agent_thread);
+    result = jvmti_env->GetThreadInfo(g_agent_thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: JNI: GetThreadInfo failed\n");
+    }
+
+    result = jvmti_env->RunAgentThread(g_agent_thread, test_function, NULL, JVMTI_THREAD_NORM_PRIORITY);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: jvmti: RunAgentThread failed\n");
+        return;
+    }*/
+}
+/*
+JNIEXPORT jint
+JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
+{
+    jint res;
+    jvmtiEnv* jvmti_env = NULL;
+
+    res = jvm->GetEnv((void**)&jvmti_env, JVMTI_VERSION_1_0);
+    if (res != JNI_OK || jvmti_env == NULL)
+        return JNI_ERR;
+
+    jvmtiEventCallbacks callbacks;
+    callbacks.ThreadStart=&ThreadStart;
+
+    jvmti_env->SetEventCallbacks(&callbacks, sizeof(callbacks));
+    jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL);
+
+    return JNI_OK;
+}
+*/
+/* *********************************************************************** */
+
+JNIEXPORT jint JNICALL Agent_OnLoad(prms_AGENT_ONLOAD)
+{
+
+    Callbacks CB;
+    CB.cbThreadStart = &ThreadStart;
+    check_AGENT_ONLOAD;
+    jvmtiEvent events[] = { JVMTI_EVENT_EXCEPTION, JVMTI_EVENT_THREAD_START, JVMTI_EVENT_VM_DEATH };
+    cb_exc;
+    cb_death;
+    return func_for_Agent_OnLoad(vm, options, reserved, &CB,
+        events, sizeof(events)/sizeof(jvmtiEvent), test_case_name, DEBUG_OUT);
+}
+
+/* *********************************************************************** */
+
+void JNICALL callbackException(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+                               jthread thread, jmethodID method,
+                               jlocation location, jobject exception,
+                               jmethodID catch_method, jlocation catch_location)
+{
+    check_EXCPT;
+    if (flag) return;
+
+    /*
+     * Function separate all other exceptions in all other method
+     */
+    if (!check_phase_and_method_debug(jvmti_env, method, SPP_LIVE_ONLY,
+                "special_method", DEBUG_OUT)) return;
+
+    flag = true;
+    util = true;
+
+    fprintf(stderr, "agent... \n");
+    SLEEP_UNIVERSAL(300);
+    ////////////////////ncai env get
+    jvmtiError err;
+    ncaiError ncai_err;
+
+    jvmtiExtensionFunctionInfo* ext_info = NULL;
+    jint ext_count = 0;
+
+    err = jvmti_env->GetExtensionFunctions(&ext_count, &ext_info);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (ext_count == 0 || ext_info == NULL)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned no extensions\n");
+        test = false;
+        return;
+    }
+
+    jvmtiExtensionFunction get_ncai_func = NULL;
+
+    fprintf(stderr, "agent... \n");
+    for (int k = 0; k < ext_count; k++)
+    {
+        if (strcmp(ext_info[k].id, "org.apache.harmony.vm.GetExtensionEnv") == 0)
+        {
+            get_ncai_func = ext_info[k].func;
+            break;
+        }
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (get_ncai_func == NULL)
+    {
+        fprintf(stderr, "test_function: GetNCAIEnvironment() nas not been found among JVMTI extensions\n");
+        test = false;
+        return;
+    }
+
+    ncaiEnv* ncai_env = NULL;
+
+    fprintf(stderr, "agent... \n");
+    err = get_ncai_func(jvmti_env, &ncai_env, NCAI_VERSION_1_0);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    if (ncai_env == NULL)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned NULL environment\n");
+        test = false;
+        return;
+    }
+    fprintf(stderr, "agent... \n");
+    ///////////////////////////////////
+    ncaiThread ncai_thread;
+
+    fprintf(stderr, "calling ncai->GetThreadHandle()...\n");
+    ncai_err = ncai_env->GetThreadHandle(g_thread_jthread, &ncai_thread);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->GetThreadHandle() returned error: %d", ncai_err);
+        test = false;
+        return;
+    }
+
+    ncaiThread* threads;
+    jint returned;
+
+    while(!g_resume_agent_thread)
+            SLEEP_UNIVERSAL(200);
+
+    g_resume_agent_thread = 0;
+
+    //////////////////////////
+    test = false;
+    ncai_err = ncai_env->GetAllThreads(&returned, &threads);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->GetAllThreads() returned error: %d", ncai_err);
+        test = false;
+        return;
+    }
+    ncaiThreadInfo info1;
+    ncai_err = ncai_env->GetThreadInfo(ncai_thread, &info1);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->GetThreadInfo() returned error: %d", ncai_err);
+        test = false;
+        return;
+    }
+
+    for(int i = 0; i < returned; i++)
+    {
+        ncaiThreadInfo info2;
+        ncai_err = ncai_env->GetThreadInfo(threads[i], &info2);
+        if (ncai_err != NCAI_ERROR_NONE)
+        {
+            fprintf(stderr, "ncai->GetThreadInfo() returned error: %d", ncai_err);
+            test = false;
+            return;
+        }
+        if(info1.kind == info2.kind && strcmp(info1.name, info2.name) == 0)
+        {
+            test = true;
+            fprintf(stderr, "\nMATCH with '%s(%d)'\n", info2.name, info2. kind);
+        }
+    }
+
+    //////////////////////////
+    g_stop_thread = 1;
+    SLEEP_UNIVERSAL(400);
+
+}
+
+void JNICALL callbackVMDeath(prms_VMDEATH)
+{
+    check_VMDEATH;
+    func_for_callback_VMDeath(jni_env, jvmti_env, test_case_name, test, util);
+}
+
+/* *********************************************************************** */
+
+void Test1(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test1(env, obj);
+
+    fprintf(stderr, "thread - pure native Test1\n");
+    return Test2(env, obj);
+}
+
+void Test2(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test2(env, obj);
+
+    fprintf(stderr, "thread - pure native Test2\n");
+    return Test3(env, obj);
+}
+
+void Test3(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test3(env, obj);
+
+    fprintf(stderr, "thread - pure native Test3\n");
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetStaticMethodID(clazz, "sleep", "(J)V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetStaticMethodID for 'sleep' failed\n");
+        return;
+    }
+
+    g_resume_agent_thread = 1;
+    while(!g_stop_thread)
+    {
+        fprintf(stderr, "thread... \n");
+        SLEEP_UNIVERSAL(100);
+//        env->CallStaticVoidMethod(clazz, mid, 500);
+    }
+    return;
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01/GetThreadHandle01.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01/GetThreadHandle01.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01/GetThreadHandle01.java?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01/GetThreadHandle01.java (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01/GetThreadHandle01.java Wed Nov 21 08:29:40 2007
@@ -0,0 +1,82 @@
+package ncai.funcs;
+
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+public class GetThreadHandle01 extends Thread{
+    public native void TestFunction();
+    public native void TestFunction1();
+    public static native boolean stopsignal();
+    public static native void resumeagent();
+
+    static boolean NoLibrary = false;
+    static {
+        try{
+            System.loadLibrary("GetThreadHandle01");
+        }
+        catch(Throwable e){
+            NoLibrary = true;
+        }
+    }
+
+    GetThreadHandle01(String name)
+    {
+        super(name);
+    }
+
+    static public void main(String args[]) {
+        if(NoLibrary) return;
+        new GetThreadHandle01("java_thread").start();
+        special_method();
+        /*
+        while(!stopsignal()){
+            try {
+                sleep(100, 0); // milliseconds
+            } catch (java.lang.InterruptedException ie) {}
+            System.out.println("\tJAVA: main: ...");
+        }
+
+        try {
+            sleep(1000, 0); // milliseconds
+        } catch (java.lang.InterruptedException ie) {}
+
+        System.out.println("\tJAVA: main - exit");
+
+*/
+        return;
+    }
+
+    public void test_java_func1(){
+        System.out.println("thread - java func1\n");
+        TestFunction();
+    }
+
+    public void test_java_func2(){
+        System.out.println("thread - java func2\n");
+        test_java_func3();
+    }
+
+    public void test_java_func3(){
+        System.out.println("thread - java func3\n");
+        TestFunction1();
+   }
+
+    static public void special_method() {
+        /*
+         * Transfer control to native part.
+         */
+        try {
+            throw new InterruptedException();
+        } catch (Throwable tex) { }
+        return;
+    }
+
+    public void run() {
+        System.out.println("thread - java run\n");
+        test_java_func1();
+    }
+}
+
+

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01/GetThreadHandle01.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01n/GetThreadHandle01n.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01n/GetThreadHandle01n.cpp?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01n/GetThreadHandle01n.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01n/GetThreadHandle01n.cpp Wed Nov 21 08:29:40 2007
@@ -0,0 +1,355 @@
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+
+/* *********************************************************************** */
+
+#include "events.h"
+#include "utils.h"
+#include "ncai.h"
+
+#ifdef POSIX
+#include <stdlib.h>
+#include <time.h>
+#else
+#include <windows.h>
+#include <CRTDBG.H>
+#endif
+
+#ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  { timespec delay = {(_x_)/1000, 1000000*((_x_)%1000)}; nanosleep(&delay, NULL); }
+#else // #ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  Sleep((_x_))
+#endif // #ifdef POSIX
+
+static int g_stop_thread = 0;
+static volatile int g_resume_agent_thread = 0;
+static jthread g_thread_jthread;
+//static jthread g_agent_thread;
+
+static volatile int no_opt = 1; //used to prevent inlining;
+
+//static int counter = 0;
+
+static bool test = false;
+static bool util = false;
+static bool flag = false;
+
+static const char test_case_name[] = "GetThreadHandle01n";
+
+static void Test1(JNIEnv *env, jobject obj);
+static void Test2(JNIEnv *env, jobject obj);
+static void Test3(JNIEnv *env, jobject obj);
+//static void JNICALL test_function(jvmtiEnv*, JNIEnv*, void*);
+//static bool CheckSuspend(ncaiEnv*, ncaiThread);
+
+extern "C" JNIEXPORT void JNICALL
+Java_ncai_funcs_GetThreadHandle01n_resumeagent(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    g_resume_agent_thread = 1;
+}
+
+extern "C" JNIEXPORT jboolean JNICALL
+Java_ncai_funcs_GetThreadHandle01n_stopsignal(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    return g_stop_thread ? true : false;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetThreadHandle01n_TestFunction
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction\n");
+
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetMethodID(clazz, "test_java_func2", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetStaticMethodID for 'test_java_func2' failed\n");
+        return;
+    }
+    env->CallVoidMethod(obj, mid);
+    return;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetThreadHandle01n_TestFunction1
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction1\n");
+    Test1(env, obj);
+    return;
+}
+
+void JNICALL ThreadStart(jvmtiEnv *jvmti_env,
+            JNIEnv* jni_env,
+            jthread thread)
+{
+    jvmtiPhase phase;
+    jvmtiError result;
+    jvmtiThreadInfo tinfo;
+
+    result = jvmti_env->GetPhase(&phase);
+    if (result != JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE)
+        return;
+
+    result = jvmti_env->GetThreadInfo(thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+        return;
+
+    if (strcmp(tinfo.name, "java_thread") != 0)
+        return;
+
+    printf("ThreadStart: java_thread\n");
+    g_thread_jthread = jni_env->NewGlobalRef(thread);
+/*
+    jclass clazz = jni_env->FindClass("java/lang/Thread");
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: JNI: FindClass failed\n");
+        return;
+    }
+
+    jmethodID mid = jni_env->GetMethodID(clazz, "<init>", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: JNI: GetMethodID failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewObject(clazz, mid, "native_agent_thread");
+    if (!g_agent_thread)
+    {
+        fprintf(stderr, "\tnative: JNI: NewObject failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewGlobalRef(g_agent_thread);
+    result = jvmti_env->GetThreadInfo(g_agent_thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: JNI: GetThreadInfo failed\n");
+    }
+
+    result = jvmti_env->RunAgentThread(g_agent_thread, test_function, NULL, JVMTI_THREAD_NORM_PRIORITY);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: jvmti: RunAgentThread failed\n");
+        return;
+    }*/
+}
+/*
+JNIEXPORT jint
+JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
+{
+    jint res;
+    jvmtiEnv* jvmti_env = NULL;
+
+    res = jvm->GetEnv((void**)&jvmti_env, JVMTI_VERSION_1_0);
+    if (res != JNI_OK || jvmti_env == NULL)
+        return JNI_ERR;
+
+    jvmtiEventCallbacks callbacks;
+    callbacks.ThreadStart=&ThreadStart;
+
+    jvmti_env->SetEventCallbacks(&callbacks, sizeof(callbacks));
+    jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL);
+
+    return JNI_OK;
+}
+*/
+/* *********************************************************************** */
+
+JNIEXPORT jint JNICALL Agent_OnLoad(prms_AGENT_ONLOAD)
+{
+
+    Callbacks CB;
+    CB.cbThreadStart = &ThreadStart;
+    check_AGENT_ONLOAD;
+    jvmtiEvent events[] = { JVMTI_EVENT_EXCEPTION, JVMTI_EVENT_THREAD_START, JVMTI_EVENT_VM_DEATH };
+    cb_exc;
+    cb_death;
+    return func_for_Agent_OnLoad(vm, options, reserved, &CB,
+        events, sizeof(events)/sizeof(jvmtiEvent), test_case_name, DEBUG_OUT);
+}
+
+/* *********************************************************************** */
+
+void JNICALL callbackException(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+                               jthread thread, jmethodID method,
+                               jlocation location, jobject exception,
+                               jmethodID catch_method, jlocation catch_location)
+{
+    check_EXCPT;
+    if (flag) return;
+
+    /*
+     * Function separate all other exceptions in all other method
+     */
+    if (!check_phase_and_method_debug(jvmti_env, method, SPP_LIVE_ONLY,
+                "special_method", DEBUG_OUT)) return;
+
+    flag = true;
+    util = true;
+
+    fprintf(stderr, "agent... \n");
+    SLEEP_UNIVERSAL(300);
+    ////////////////////ncai env get
+    jvmtiError err;
+    ncaiError ncai_err;
+
+    jvmtiExtensionFunctionInfo* ext_info = NULL;
+    jint ext_count = 0;
+
+    err = jvmti_env->GetExtensionFunctions(&ext_count, &ext_info);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (ext_count == 0 || ext_info == NULL)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned no extensions\n");
+        test = false;
+        return;
+    }
+
+    jvmtiExtensionFunction get_ncai_func = NULL;
+
+    fprintf(stderr, "agent... \n");
+    for (int k = 0; k < ext_count; k++)
+    {
+        if (strcmp(ext_info[k].id, "org.apache.harmony.vm.GetExtensionEnv") == 0)
+        {
+            get_ncai_func = ext_info[k].func;
+            break;
+        }
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (get_ncai_func == NULL)
+    {
+        fprintf(stderr, "test_function: GetNCAIEnvironment() nas not been found among JVMTI extensions\n");
+        test = false;
+        return;
+    }
+
+    ncaiEnv* ncai_env = NULL;
+
+    fprintf(stderr, "agent... \n");
+    err = get_ncai_func(jvmti_env, &ncai_env, NCAI_VERSION_1_0);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    if (ncai_env == NULL)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned NULL environment\n");
+        test = false;
+        return;
+    }
+    fprintf(stderr, "agent... \n");
+    ///////////////////////////////////
+
+    while(!g_resume_agent_thread)
+            SLEEP_UNIVERSAL(200);
+
+    g_resume_agent_thread = 0;
+    test = true;
+
+    fprintf(stderr, "calling ncai->GetThreadHandle()...\n");
+    ncai_err = ncai_env->GetThreadHandle(g_thread_jthread, NULL);
+    if (ncai_err != NCAI_ERROR_NULL_POINTER)
+    {
+        fprintf(stderr, "ncai->GetThreadHandle() returned invalid error: %d", ncai_err);
+        test = false;
+        g_stop_thread = 1;
+        return;
+    }
+
+    g_stop_thread = 1;
+    SLEEP_UNIVERSAL(400);
+
+}
+
+void JNICALL callbackVMDeath(prms_VMDEATH)
+{
+    check_VMDEATH;
+    func_for_callback_VMDeath(jni_env, jvmti_env, test_case_name, test, util);
+}
+
+/* *********************************************************************** */
+
+void Test1(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test1(env, obj);
+
+    fprintf(stderr, "thread - pure native Test1\n");
+    return Test2(env, obj);
+}
+
+void Test2(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test2(env, obj);
+
+    fprintf(stderr, "thread - pure native Test2\n");
+    return Test3(env, obj);
+}
+
+void Test3(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test3(env, obj);
+
+    fprintf(stderr, "thread - pure native Test3\n");
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetStaticMethodID(clazz, "sleep", "(J)V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetStaticMethodID for 'sleep' failed\n");
+        return;
+    }
+
+    g_resume_agent_thread = 1;
+    while(!g_stop_thread)
+    {
+        fprintf(stderr, "thread... \n");
+        SLEEP_UNIVERSAL(100);
+//        env->CallStaticVoidMethod(clazz, mid, 500);
+    }
+    return;
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01n/GetThreadHandle01n.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01n/GetThreadHandle01n.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01n/GetThreadHandle01n.java?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01n/GetThreadHandle01n.java (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01n/GetThreadHandle01n.java Wed Nov 21 08:29:40 2007
@@ -0,0 +1,82 @@
+package ncai.funcs;
+
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+public class GetThreadHandle01n extends Thread{
+    public native void TestFunction();
+    public native void TestFunction1();
+    public static native boolean stopsignal();
+    public static native void resumeagent();
+
+    static boolean NoLibrary = false;
+    static {
+        try{
+            System.loadLibrary("GetThreadHandle01n");
+        }
+        catch(Throwable e){
+            NoLibrary = true;
+        }
+    }
+
+    GetThreadHandle01n(String name)
+    {
+        super(name);
+    }
+
+    static public void main(String args[]) {
+        if(NoLibrary) return;
+        new GetThreadHandle01n("java_thread").start();
+        special_method();
+        /*
+        while(!stopsignal()){
+            try {
+                sleep(100, 0); // milliseconds
+            } catch (java.lang.InterruptedException ie) {}
+            System.out.println("\tJAVA: main: ...");
+        }
+
+        try {
+            sleep(1000, 0); // milliseconds
+        } catch (java.lang.InterruptedException ie) {}
+
+        System.out.println("\tJAVA: main - exit");
+
+*/
+        return;
+    }
+
+    public void test_java_func1(){
+        System.out.println("thread - java func1\n");
+        TestFunction();
+    }
+
+    public void test_java_func2(){
+        System.out.println("thread - java func2\n");
+        test_java_func3();
+    }
+
+    public void test_java_func3(){
+        System.out.println("thread - java func3\n");
+        TestFunction1();
+   }
+
+    static public void special_method() {
+        /*
+         * Transfer control to native part.
+         */
+        try {
+            throw new InterruptedException();
+        } catch (Throwable tex) { }
+        return;
+    }
+
+    public void run() {
+        System.out.println("thread - java run\n");
+        test_java_func1();
+    }
+}
+
+

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle01n/GetThreadHandle01n.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02/GetThreadHandle02.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02/GetThreadHandle02.cpp?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02/GetThreadHandle02.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02/GetThreadHandle02.cpp Wed Nov 21 08:29:40 2007
@@ -0,0 +1,415 @@
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+
+/* *********************************************************************** */
+
+#include "events.h"
+#include "utils.h"
+#include "ncai.h"
+
+#ifdef POSIX
+#include <stdlib.h>
+#include <time.h>
+#else
+#include <windows.h>
+#include <CRTDBG.H>
+#endif
+
+#ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  { timespec delay = {(_x_)/1000, 1000000*((_x_)%1000)}; nanosleep(&delay, NULL); }
+#else // #ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  Sleep((_x_))
+#endif // #ifdef POSIX
+
+static int g_stop_thread = 0;
+static volatile int g_resume_agent_thread = 0;
+static jthread g_thread_jthread;
+//static jthread g_agent_thread;
+
+static volatile int no_opt = 1; //used to prevent inlining;
+
+//static int counter = 0;
+
+static bool test = false;
+static bool util = false;
+static bool flag = false;
+
+static const char test_case_name[] = "GetThreadHandle02";
+
+static void Test1(JNIEnv *env, jobject obj);
+static void Test2(JNIEnv *env, jobject obj);
+static void Test3(JNIEnv *env, jobject obj);
+//static void JNICALL test_function(jvmtiEnv*, JNIEnv*, void*);
+//static bool CheckSuspend(ncaiEnv*, ncaiThread);
+
+extern "C" JNIEXPORT void JNICALL
+Java_ncai_funcs_GetThreadHandle02_resumeagent(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    g_resume_agent_thread = 1;
+}
+
+extern "C" JNIEXPORT jboolean JNICALL
+Java_ncai_funcs_GetThreadHandle02_stopsignal(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    return g_stop_thread ? true : false;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetThreadHandle02_TestFunction
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction\n");
+
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetMethodID(clazz, "test_java_func2", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetStaticMethodID for 'test_java_func2' failed\n");
+        return;
+    }
+    env->CallVoidMethod(obj, mid);
+    return;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetThreadHandle02_TestFunction1
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction1\n");
+    Test1(env, obj);
+    return;
+}
+
+void JNICALL ThreadStart(jvmtiEnv *jvmti_env,
+            JNIEnv* jni_env,
+            jthread thread)
+{
+    jvmtiPhase phase;
+    jvmtiError result;
+    jvmtiThreadInfo tinfo;
+
+    result = jvmti_env->GetPhase(&phase);
+    if (result != JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE)
+        return;
+
+    result = jvmti_env->GetThreadInfo(thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+        return;
+
+    if (strcmp(tinfo.name, "java_thread") != 0)
+        return;
+
+    printf("ThreadStart: java_thread\n");
+    g_thread_jthread = jni_env->NewGlobalRef(thread);
+/*
+    jclass clazz = jni_env->FindClass("java/lang/Thread");
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: JNI: FindClass failed\n");
+        return;
+    }
+
+    jmethodID mid = jni_env->GetMethodID(clazz, "<init>", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: JNI: GetMethodID failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewObject(clazz, mid, "native_agent_thread");
+    if (!g_agent_thread)
+    {
+        fprintf(stderr, "\tnative: JNI: NewObject failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewGlobalRef(g_agent_thread);
+    result = jvmti_env->GetThreadInfo(g_agent_thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: JNI: GetThreadInfo failed\n");
+    }
+
+    result = jvmti_env->RunAgentThread(g_agent_thread, test_function, NULL, JVMTI_THREAD_NORM_PRIORITY);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: jvmti: RunAgentThread failed\n");
+        return;
+    }*/
+}
+/*
+JNIEXPORT jint
+JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
+{
+    jint res;
+    jvmtiEnv* jvmti_env = NULL;
+
+    res = jvm->GetEnv((void**)&jvmti_env, JVMTI_VERSION_1_0);
+    if (res != JNI_OK || jvmti_env == NULL)
+        return JNI_ERR;
+
+    jvmtiEventCallbacks callbacks;
+    callbacks.ThreadStart=&ThreadStart;
+
+    jvmti_env->SetEventCallbacks(&callbacks, sizeof(callbacks));
+    jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL);
+
+    return JNI_OK;
+}
+*/
+/* *********************************************************************** */
+
+JNIEXPORT jint JNICALL Agent_OnLoad(prms_AGENT_ONLOAD)
+{
+
+    Callbacks CB;
+    CB.cbThreadStart = &ThreadStart;
+    check_AGENT_ONLOAD;
+    jvmtiEvent events[] = { JVMTI_EVENT_EXCEPTION, JVMTI_EVENT_THREAD_START, JVMTI_EVENT_VM_DEATH };
+    cb_exc;
+    cb_death;
+    return func_for_Agent_OnLoad(vm, options, reserved, &CB,
+        events, sizeof(events)/sizeof(jvmtiEvent), test_case_name, DEBUG_OUT);
+}
+
+/* *********************************************************************** */
+
+void JNICALL callbackException(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+                               jthread thread, jmethodID method,
+                               jlocation location, jobject exception,
+                               jmethodID catch_method, jlocation catch_location)
+{
+    check_EXCPT;
+    if (flag) return;
+
+    /*
+     * Function separate all other exceptions in all other method
+     */
+    if (!check_phase_and_method_debug(jvmti_env, method, SPP_LIVE_ONLY,
+                "special_method", DEBUG_OUT)) return;
+
+    flag = true;
+    util = true;
+
+    fprintf(stderr, "agent... \n");
+    SLEEP_UNIVERSAL(300);
+    ////////////////////ncai env get
+    jvmtiError err;
+    ncaiError ncai_err;
+
+    jvmtiExtensionFunctionInfo* ext_info = NULL;
+    jint ext_count = 0;
+
+    err = jvmti_env->GetExtensionFunctions(&ext_count, &ext_info);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (ext_count == 0 || ext_info == NULL)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned no extensions\n");
+        test = false;
+        return;
+    }
+
+    jvmtiExtensionFunction get_ncai_func = NULL;
+
+    fprintf(stderr, "agent... \n");
+    for (int k = 0; k < ext_count; k++)
+    {
+        if (strcmp(ext_info[k].id, "org.apache.harmony.vm.GetExtensionEnv") == 0)
+        {
+            get_ncai_func = ext_info[k].func;
+            break;
+        }
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (get_ncai_func == NULL)
+    {
+        fprintf(stderr, "test_function: GetNCAIEnvironment() nas not been found among JVMTI extensions\n");
+        test = false;
+        return;
+    }
+
+    ncaiEnv* ncai_env = NULL;
+
+    fprintf(stderr, "agent... \n");
+    err = get_ncai_func(jvmti_env, &ncai_env, NCAI_VERSION_1_0);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    if (ncai_env == NULL)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned NULL environment\n");
+        test = false;
+        return;
+    }
+    fprintf(stderr, "agent... \n");
+    ///////////////////////////////////
+    ncaiThread ncai_thread;
+
+    fprintf(stderr, "calling ncai->GetThreadHandle()...\n");
+    ncai_err = ncai_env->GetThreadHandle(g_thread_jthread, &ncai_thread);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->GetThreadHandle() returned error: %d", ncai_err);
+        test = false;
+        return;
+    }
+
+    ncaiThread* threads;
+    jint returned;
+
+    while(!g_resume_agent_thread)
+            SLEEP_UNIVERSAL(200);
+
+    g_resume_agent_thread = 0;
+
+    //////////////////////////
+    test = false;
+    ncai_err = ncai_env->GetAllThreads(&returned, &threads);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->GetAllThreads() returned error: %d", ncai_err);
+        test = false;
+        g_stop_thread = 1;
+        return;
+    }
+    ncaiThreadInfo info1;
+    ncai_err = ncai_env->GetThreadInfo(ncai_thread, &info1);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->GetThreadInfo() returned error: %d", ncai_err);
+        test = false;
+        g_stop_thread = 1;
+        return;
+    }
+
+    ncai_err = ncai_env->SuspendThread(ncai_thread);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->SuspendThread() returned error: %d", ncai_err);
+        test = false;
+        g_stop_thread = 1;
+        return;
+    }
+    fprintf(stderr, "\nncai->SuspendThread()...");
+
+    for(int i = 0; i < returned; i++)
+    {
+        ncaiThreadInfo info2;
+        ncai_err = ncai_env->GetThreadInfo(threads[i], &info2);
+        if (ncai_err != NCAI_ERROR_NONE)
+        {
+            fprintf(stderr, "ncai->GetThreadInfo() returned error: %d", ncai_err);
+            test = false;
+            g_stop_thread = 1;
+            return;
+        }
+        if(info1.kind == info2.kind && strcmp(info1.name, info2.name) == 0)
+        {
+            test = true;
+            fprintf(stderr, "\nMATCH with '%s(%d)'", info2.name, info2. kind);
+        }
+    }
+
+    ncai_err = ncai_env->ResumeThread(ncai_thread);
+    if (ncai_err != NCAI_ERROR_NONE)
+    {
+        fprintf(stderr, "ncai->ResumeThread() returned error: %d", ncai_err);
+        test = false;
+        g_stop_thread = 1;
+        return;
+    }
+    fprintf(stderr, "\nncai->ResumeThread()...\n");
+    //////////////////////////
+    g_stop_thread = 1;
+    SLEEP_UNIVERSAL(400);
+
+}
+
+void JNICALL callbackVMDeath(prms_VMDEATH)
+{
+    check_VMDEATH;
+    func_for_callback_VMDeath(jni_env, jvmti_env, test_case_name, test, util);
+}
+
+/* *********************************************************************** */
+
+void Test1(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test1(env, obj);
+
+    fprintf(stderr, "thread - pure native Test1\n");
+    return Test2(env, obj);
+}
+
+void Test2(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test2(env, obj);
+
+    fprintf(stderr, "thread - pure native Test2\n");
+    return Test3(env, obj);
+}
+
+void Test3(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test3(env, obj);
+
+    fprintf(stderr, "thread - pure native Test3\n");
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetStaticMethodID(clazz, "sleep", "(J)V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetStaticMethodID for 'sleep' failed\n");
+        return;
+    }
+
+    g_resume_agent_thread = 1;
+    while(!g_stop_thread)
+    {
+        fprintf(stderr, "thread... \n");
+        SLEEP_UNIVERSAL(100);
+//        env->CallStaticVoidMethod(clazz, mid, 500);
+    }
+    return;
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02/GetThreadHandle02.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02/GetThreadHandle02.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02/GetThreadHandle02.java?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02/GetThreadHandle02.java (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02/GetThreadHandle02.java Wed Nov 21 08:29:40 2007
@@ -0,0 +1,82 @@
+package ncai.funcs;
+
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+public class GetThreadHandle02 extends Thread{
+    public native void TestFunction();
+    public native void TestFunction1();
+    public static native boolean stopsignal();
+    public static native void resumeagent();
+
+    static boolean NoLibrary = false;
+    static {
+        try{
+            System.loadLibrary("GetThreadHandle02");
+        }
+        catch(Throwable e){
+            NoLibrary = true;
+        }
+    }
+
+    GetThreadHandle02(String name)
+    {
+        super(name);
+    }
+
+    static public void main(String args[]) {
+        if(NoLibrary) return;
+        new GetThreadHandle02("java_thread").start();
+        special_method();
+        /*
+        while(!stopsignal()){
+            try {
+                sleep(100, 0); // milliseconds
+            } catch (java.lang.InterruptedException ie) {}
+            System.out.println("\tJAVA: main: ...");
+        }
+
+        try {
+            sleep(1000, 0); // milliseconds
+        } catch (java.lang.InterruptedException ie) {}
+
+        System.out.println("\tJAVA: main - exit");
+
+*/
+        return;
+    }
+
+    public void test_java_func1(){
+        System.out.println("thread - java func1\n");
+        TestFunction();
+    }
+
+    public void test_java_func2(){
+        System.out.println("thread - java func2\n");
+        test_java_func3();
+    }
+
+    public void test_java_func3(){
+        System.out.println("thread - java func3\n");
+        TestFunction1();
+   }
+
+    static public void special_method() {
+        /*
+         * Transfer control to native part.
+         */
+        try {
+            throw new InterruptedException();
+        } catch (Throwable tex) { }
+        return;
+    }
+
+    public void run() {
+        System.out.println("thread - java run\n");
+        test_java_func1();
+    }
+}
+
+

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02/GetThreadHandle02.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02n/GetThreadHandle02n.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02n/GetThreadHandle02n.cpp?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02n/GetThreadHandle02n.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02n/GetThreadHandle02n.cpp Wed Nov 21 08:29:40 2007
@@ -0,0 +1,361 @@
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+
+/* *********************************************************************** */
+
+#include "events.h"
+#include "utils.h"
+#include "ncai.h"
+
+#ifdef POSIX
+#include <stdlib.h>
+#include <time.h>
+#else
+#include <windows.h>
+#include <CRTDBG.H>
+#endif
+
+#ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  { timespec delay = {(_x_)/1000, 1000000*((_x_)%1000)}; nanosleep(&delay, NULL); }
+#else // #ifdef POSIX
+#define SLEEP_UNIVERSAL(_x_)  Sleep((_x_))
+#endif // #ifdef POSIX
+
+static int g_stop_thread = 0;
+static volatile int g_resume_agent_thread = 0;
+//static jthread g_thread_jthread;
+//static jthread g_agent_thread;
+
+static volatile int no_opt = 1; //used to prevent inlining;
+
+//static int counter = 0;
+
+static bool test = false;
+static bool util = false;
+static bool flag = false;
+
+static const char test_case_name[] = "GetThreadHandle02n";
+
+static void Test1(JNIEnv *env, jobject obj);
+static void Test2(JNIEnv *env, jobject obj);
+static void Test3(JNIEnv *env, jobject obj);
+//static void JNICALL test_function(jvmtiEnv*, JNIEnv*, void*);
+//static bool CheckSuspend(ncaiEnv*, ncaiThread);
+
+extern "C" JNIEXPORT void JNICALL
+Java_ncai_funcs_GetThreadHandle02n_resumeagent(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    g_resume_agent_thread = 1;
+}
+
+extern "C" JNIEXPORT jboolean JNICALL
+Java_ncai_funcs_GetThreadHandle02n_stopsignal(JNIEnv *env, jclass cls)
+{
+    //warning fix
+    int w_fix = sizeof(cls);
+    w_fix += sizeof(env);
+    //
+
+    return g_stop_thread ? true : false;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetThreadHandle02n_TestFunction
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction\n");
+
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetMethodID(clazz, "test_java_func2", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction: GetStaticMethodID for 'test_java_func2' failed\n");
+        return;
+    }
+    env->CallVoidMethod(obj, mid);
+    return;
+}
+
+extern "C" JNIEXPORT void JNICALL Java_ncai_funcs_GetThreadHandle02n_TestFunction1
+  (JNIEnv *env, jobject obj)
+{
+    fprintf(stderr, "thread - native TestFunction1\n");
+    Test1(env, obj);
+    return;
+}
+
+void JNICALL ThreadStart(jvmtiEnv *jvmti_env,
+            JNIEnv* jni_env,
+            jthread thread)
+{
+    //warning fix
+    int w_fix = 0;
+    w_fix += sizeof(jni_env);
+    //
+
+    jvmtiPhase phase;
+    jvmtiError result;
+    jvmtiThreadInfo tinfo;
+
+    result = jvmti_env->GetPhase(&phase);
+    if (result != JVMTI_ERROR_NONE || phase != JVMTI_PHASE_LIVE)
+        return;
+
+    result = jvmti_env->GetThreadInfo(thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+        return;
+
+    if (strcmp(tinfo.name, "java_thread") != 0)
+        return;
+
+    printf("ThreadStart: java_thread\n");
+/*    g_thread_jthread = jni_env->NewGlobalRef(thread);
+
+    jclass clazz = jni_env->FindClass("java/lang/Thread");
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: JNI: FindClass failed\n");
+        return;
+    }
+
+    jmethodID mid = jni_env->GetMethodID(clazz, "<init>", "()V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: JNI: GetMethodID failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewObject(clazz, mid, "native_agent_thread");
+    if (!g_agent_thread)
+    {
+        fprintf(stderr, "\tnative: JNI: NewObject failed\n");
+        return;
+    }
+
+    g_agent_thread = jni_env->NewGlobalRef(g_agent_thread);
+    result = jvmti_env->GetThreadInfo(g_agent_thread, &tinfo);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: JNI: GetThreadInfo failed\n");
+    }
+
+    result = jvmti_env->RunAgentThread(g_agent_thread, test_function, NULL, JVMTI_THREAD_NORM_PRIORITY);
+    if (result != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "\tnative: jvmti: RunAgentThread failed\n");
+        return;
+    }*/
+}
+/*
+JNIEXPORT jint
+JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
+{
+    jint res;
+    jvmtiEnv* jvmti_env = NULL;
+
+    res = jvm->GetEnv((void**)&jvmti_env, JVMTI_VERSION_1_0);
+    if (res != JNI_OK || jvmti_env == NULL)
+        return JNI_ERR;
+
+    jvmtiEventCallbacks callbacks;
+    callbacks.ThreadStart=&ThreadStart;
+
+    jvmti_env->SetEventCallbacks(&callbacks, sizeof(callbacks));
+    jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL);
+
+    return JNI_OK;
+}
+*/
+/* *********************************************************************** */
+
+JNIEXPORT jint JNICALL Agent_OnLoad(prms_AGENT_ONLOAD)
+{
+
+    Callbacks CB;
+    CB.cbThreadStart = &ThreadStart;
+    check_AGENT_ONLOAD;
+    jvmtiEvent events[] = { JVMTI_EVENT_EXCEPTION, JVMTI_EVENT_THREAD_START, JVMTI_EVENT_VM_DEATH };
+    cb_exc;
+    cb_death;
+    return func_for_Agent_OnLoad(vm, options, reserved, &CB,
+        events, sizeof(events)/sizeof(jvmtiEvent), test_case_name, DEBUG_OUT);
+}
+
+/* *********************************************************************** */
+
+void JNICALL callbackException(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+                               jthread thread, jmethodID method,
+                               jlocation location, jobject exception,
+                               jmethodID catch_method, jlocation catch_location)
+{
+    check_EXCPT;
+    if (flag) return;
+
+    /*
+     * Function separate all other exceptions in all other method
+     */
+    if (!check_phase_and_method_debug(jvmti_env, method, SPP_LIVE_ONLY,
+                "special_method", DEBUG_OUT)) return;
+
+    flag = true;
+    util = true;
+
+    fprintf(stderr, "agent... \n");
+    SLEEP_UNIVERSAL(300);
+    ////////////////////ncai env get
+    jvmtiError err;
+    ncaiError ncai_err;
+
+    jvmtiExtensionFunctionInfo* ext_info = NULL;
+    jint ext_count = 0;
+
+    err = jvmti_env->GetExtensionFunctions(&ext_count, &ext_info);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (ext_count == 0 || ext_info == NULL)
+    {
+        fprintf(stderr, "test_function: GetExtensionFunctions() returned no extensions\n");
+        test = false;
+        return;
+    }
+
+    jvmtiExtensionFunction get_ncai_func = NULL;
+
+    fprintf(stderr, "agent... \n");
+    for (int k = 0; k < ext_count; k++)
+    {
+        if (strcmp(ext_info[k].id, "org.apache.harmony.vm.GetExtensionEnv") == 0)
+        {
+            get_ncai_func = ext_info[k].func;
+            break;
+        }
+    }
+
+    fprintf(stderr, "agent... \n");
+    if (get_ncai_func == NULL)
+    {
+        fprintf(stderr, "test_function: GetNCAIEnvironment() nas not been found among JVMTI extensions\n");
+        test = false;
+        return;
+    }
+
+    ncaiEnv* ncai_env = NULL;
+
+    fprintf(stderr, "agent... \n");
+    err = get_ncai_func(jvmti_env, &ncai_env, NCAI_VERSION_1_0);
+
+    if (err != JVMTI_ERROR_NONE)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned error: %d, '%s'\n",
+            err, get_jvmti_eror_text(err));
+        test = false;
+        return;
+    }
+
+    if (ncai_env == NULL)
+    {
+        fprintf(stderr, "test_function: get_ncai_func() returned NULL environment\n");
+        test = false;
+        return;
+    }
+    fprintf(stderr, "agent... \n");
+    ///////////////////////////////////
+    ncaiThread ncai_thread;
+
+    while(!g_resume_agent_thread)
+            SLEEP_UNIVERSAL(200);
+
+    g_resume_agent_thread = 0;
+    test = true;
+
+    fprintf(stderr, "calling ncai->GetThreadHandle()...\n");
+    ncai_err = ncai_env->GetThreadHandle(NULL, &ncai_thread);
+    if (ncai_err != NCAI_ERROR_INVALID_THREAD)
+    {
+        fprintf(stderr, "ncai->GetThreadHandle() returned invalid error: %d", ncai_err);
+        test = false;
+        g_stop_thread = 1;
+        return;
+    }
+
+    g_stop_thread = 1;
+    SLEEP_UNIVERSAL(400);
+
+}
+
+void JNICALL callbackVMDeath(prms_VMDEATH)
+{
+    check_VMDEATH;
+    func_for_callback_VMDeath(jni_env, jvmti_env, test_case_name, test, util);
+}
+
+/* *********************************************************************** */
+
+void Test1(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test1(env, obj);
+
+    fprintf(stderr, "thread - pure native Test1\n");
+    return Test2(env, obj);
+}
+
+void Test2(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test2(env, obj);
+
+    fprintf(stderr, "thread - pure native Test2\n");
+    return Test3(env, obj);
+}
+
+void Test3(JNIEnv *env, jobject obj)
+{
+    if(!no_opt)
+        Test3(env, obj);
+
+    fprintf(stderr, "thread - pure native Test3\n");
+    jclass clazz = env->GetObjectClass(obj);
+    if (!clazz)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetObjectClass failed\n");
+        return;
+    }
+
+    jmethodID mid = env->GetStaticMethodID(clazz, "sleep", "(J)V");
+    if (!mid)
+    {
+        fprintf(stderr, "\tnative: native TestFunction1: GetStaticMethodID for 'sleep' failed\n");
+        return;
+    }
+
+    g_resume_agent_thread = 1;
+    while(!g_stop_thread)
+    {
+        fprintf(stderr, "thread... \n");
+        SLEEP_UNIVERSAL(100);
+//        env->CallStaticVoidMethod(clazz, mid, 500);
+    }
+    return;
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02n/GetThreadHandle02n.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02n/GetThreadHandle02n.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02n/GetThreadHandle02n.java?rev=597138&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02n/GetThreadHandle02n.java (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02n/GetThreadHandle02n.java Wed Nov 21 08:29:40 2007
@@ -0,0 +1,82 @@
+package ncai.funcs;
+
+/**
+ * @author Petr Ivanov
+ * @version $Revision: 1.1.1.1 $
+ *
+ */
+public class GetThreadHandle02n extends Thread{
+    public native void TestFunction();
+    public native void TestFunction1();
+    public static native boolean stopsignal();
+    public static native void resumeagent();
+
+    static boolean NoLibrary = false;
+    static {
+        try{
+            System.loadLibrary("GetThreadHandle02n");
+        }
+        catch(Throwable e){
+            NoLibrary = true;
+        }
+    }
+
+    GetThreadHandle02n(String name)
+    {
+        super(name);
+    }
+
+    static public void main(String args[]) {
+        if(NoLibrary) return;
+        new GetThreadHandle02n("java_thread").start();
+        special_method();
+        /*
+        while(!stopsignal()){
+            try {
+                sleep(100, 0); // milliseconds
+            } catch (java.lang.InterruptedException ie) {}
+            System.out.println("\tJAVA: main: ...");
+        }
+
+        try {
+            sleep(1000, 0); // milliseconds
+        } catch (java.lang.InterruptedException ie) {}
+
+        System.out.println("\tJAVA: main - exit");
+
+*/
+        return;
+    }
+
+    public void test_java_func1(){
+        System.out.println("thread - java func1\n");
+        TestFunction();
+    }
+
+    public void test_java_func2(){
+        System.out.println("thread - java func2\n");
+        test_java_func3();
+    }
+
+    public void test_java_func3(){
+        System.out.println("thread - java func3\n");
+        TestFunction1();
+   }
+
+    static public void special_method() {
+        /*
+         * Transfer control to native part.
+         */
+        try {
+            throw new InterruptedException();
+        } catch (Throwable tex) { }
+        return;
+    }
+
+    public void run() {
+        System.out.println("thread - java run\n");
+        test_java_func1();
+    }
+}
+
+

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/ncai/funcs/GetThreadHandle/GetThreadHandle02n/GetThreadHandle02n.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message