harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r527239 - in /harmony/enhanced/drlvm/trunk: build/make/excludes/ vm/tests/jvmti/PopFrame1/
Date Tue, 10 Apr 2007 18:28:13 GMT
Author: gshimansky
Date: Tue Apr 10 11:28:12 2007
New Revision: 527239

URL: http://svn.apache.org/viewvc?view=rev&rev=527239
Log:
Added test from HARMONY-2749


Added:
    harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/
    harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/PopFrame1.java   (with props)
    harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.cpp   (with props)
    harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.h   (with props)
    harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/popframe.cpp   (with props)
Modified:
    harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.linux.x86.opt
    harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.linux.x86.srv
    harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.windows.x86.opt
    harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.windows.x86.srv

Modified: harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.linux.x86.opt
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.linux.x86.opt?view=diff&rev=527239&r1=527238&r2=527239
==============================================================================
--- harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.linux.x86.opt (original)
+++ harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.linux.x86.opt Tue
Apr 10 11:28:12 2007
@@ -1,3 +1,4 @@
 Breakpoint1/Breakpoint1.java
 SingleStep1/SingleStep1.java
-VMInit1/VMInit1.java
\ No newline at end of file
+VMInit1/VMInit1.java
+PopFrame1/PopFrame1.java

Modified: harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.linux.x86.srv
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.linux.x86.srv?view=diff&rev=527239&r1=527238&r2=527239
==============================================================================
--- harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.linux.x86.srv (original)
+++ harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.linux.x86.srv Tue
Apr 10 11:28:12 2007
@@ -1,3 +1,4 @@
 Breakpoint1/Breakpoint1.java
 SingleStep1/SingleStep1.java
-VMInit1/VMInit1.java
\ No newline at end of file
+VMInit1/VMInit1.java
+PopFrame1/PopFrame1.java

Modified: harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.windows.x86.opt
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.windows.x86.opt?view=diff&rev=527239&r1=527238&r2=527239
==============================================================================
--- harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.windows.x86.opt (original)
+++ harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.windows.x86.opt Tue
Apr 10 11:28:12 2007
@@ -1,3 +1,4 @@
 Breakpoint1/Breakpoint1.java
 SingleStep1/SingleStep1.java
-VMInit1/VMInit1.java
\ No newline at end of file
+VMInit1/VMInit1.java
+PopFrame1/PopFrame1.java

Modified: harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.windows.x86.srv
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.windows.x86.srv?view=diff&rev=527239&r1=527238&r2=527239
==============================================================================
--- harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.windows.x86.srv (original)
+++ harmony/enhanced/drlvm/trunk/build/make/excludes/exclude.drlvm_jvmti.windows.x86.srv Tue
Apr 10 11:28:12 2007
@@ -1,3 +1,4 @@
 Breakpoint1/Breakpoint1.java
 SingleStep1/SingleStep1.java
-VMInit1/VMInit1.java
\ No newline at end of file
+VMInit1/VMInit1.java
+PopFrame1/PopFrame1.java

Added: harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/PopFrame1.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/PopFrame1.java?view=auto&rev=527239
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/PopFrame1.java (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/PopFrame1.java Tue Apr 10 11:28:12
2007
@@ -0,0 +1,86 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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 Pavel Rebriy
+ */
+
+package PopFrame1;
+
+import junit.framework.TestCase;
+
+public class PopFrame1 extends TestCase {
+
+	static boolean status = false;
+
+    static public void main(String args[]) {
+    	new PopFrame1().test();
+        if (status) {
+            System.out.println("Test passed!");
+        } else {
+            System.out.println("Test failed!");
+        }
+        assertTrue(status);
+    }
+    
+    public void test() {
+    	Thread inst = new Thread("Test thread") {
+	    	public void run() {
+	        	System.out.println("Test: First step!");
+	            second_step();
+	            return;
+	        }
+	
+	    	private void second_step() {
+	    		if(status) {
+	    			return;
+	    		}
+	        	System.out.println("Test: Second step!");
+	            third_step();
+	            return;
+	        }
+	
+	    	private void third_step() {
+	    		if(status) {
+	    			return;
+	    		}
+	        	System.out.println("Test: Third step!");
+	            long x = 0;
+	            for (long a = 0; a < 100000L; a++) {
+                    if(status) {
+                    	return;
+                    }
+                    x += a;
+	            }
+	            if(status) {
+	            	return;
+	            }
+	            System.out.println("Test: done!");
+	        }
+	    };
+    	inst.start();
+	    
+    	// waiting when thread is terminated
+    	try {
+        	inst.join();
+    	} catch(InterruptedException exc) {
+    		System.out.println("Main: control thread join was interruped");
+    	}
+        assertTrue(status);
+        return;
+    }
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/PopFrame1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.cpp?view=auto&rev=527239
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.cpp Tue Apr 10 11:28:12 2007
@@ -0,0 +1,113 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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 Pavel Rebriy
+ */
+
+#include "agent.h"
+
+#define CHECK_CAP(obtained, needed, jvmti_cap)              \
+    if(!obtained.jvmti_cap) {                               \
+    REPORT( "Cannot set capability: "#jvmti_cap );          \
+        return JNI_ERR;                                     \
+    }                                                       \
+    needed.jvmti_cap = 1;
+
+static inline jint
+set_agent_capabilities(jvmtiEnv * jvmti_env)
+{
+    // get VM capabilities
+    jvmtiCapabilities vm_cap;
+    jvmtiError result = jvmti_env->GetPotentialCapabilities(&vm_cap);
+    if (result != JVMTI_ERROR_NONE) {
+        REPORT( "get potential capabilities" );
+        return JNI_ERR;
+    }
+
+    jvmtiCapabilities need_cap = {0};
+    CHECK_CAP(vm_cap, need_cap, can_generate_breakpoint_events);
+    CHECK_CAP(vm_cap, need_cap, can_generate_single_step_events);
+    CHECK_CAP(vm_cap, need_cap, can_suspend);
+    CHECK_CAP(vm_cap, need_cap, can_pop_frame);
+    CHECK_CAP(vm_cap, need_cap, can_get_line_numbers);
+
+    result = jvmti_env->AddCapabilities(&need_cap);
+    if (result != JVMTI_ERROR_NONE) {
+        REPORT( "set needed capabilities" );
+        return JNI_ERR;
+    }
+    return JNI_OK;
+}
+
+static inline jint
+set_agent_events(jvmtiEnv * jvmti_env)
+{
+    jvmtiEventCallbacks callbacks;
+    memset(&callbacks, 0, sizeof(callbacks));
+
+    // set event callbacks
+    callbacks.ThreadStart = &agent_callback_ThreadStart;
+    callbacks.Breakpoint = &agent_callback_Breakpoint;
+    callbacks.SingleStep = &agent_callback_SingleStep;
+    jvmtiError result = jvmti_env->SetEventCallbacks(&callbacks, (jint)sizeof(callbacks));
+    if( result != JVMTI_ERROR_NONE ) {
+        REPORT("set events callbacks");
+        return JNI_ERR;
+    }
+
+    // set ThreadStart event
+    result = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START,
NULL);
+    if( result != JVMTI_ERROR_NONE ) {
+        REPORT("enable ThreadStart event");
+        return JNI_ERR;
+    }
+    // set Breakpoint event
+    result = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT,
NULL);
+    if( result != JVMTI_ERROR_NONE ) {
+        REPORT("enable Breakpoint event");
+        return JNI_ERR;
+    }
+
+    return JNI_OK;
+}
+
+JNIEXPORT jint JNICALL
+Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
+{
+    // get JVMTI enviroment
+    jvmtiEnv * jvmti_env;
+    DEBUG("Getting JVMTI enviroment... ");
+    if( vm->GetEnv( (void**)&jvmti_env, JVMTI_VERSION_1_0) != JNI_OK ) {
+        REPORT( "get JVMTI enviroment" );
+        return JNI_OK;
+    }
+    
+    // set capabilities
+    DEBUG("Setting capabilities... ");
+    if( set_agent_capabilities(jvmti_env) != JNI_OK ) {
+        return JNI_OK;
+    }
+
+    // set events
+    DEBUG("Setting events... ");
+    if( set_agent_events(jvmti_env) != JNI_OK ) {
+        return JNI_OK;
+    }
+
+    return JNI_OK;
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.h?view=auto&rev=527239
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.h (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.h Tue Apr 10 11:28:12 2007
@@ -0,0 +1,67 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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 Pavel Rebriy
+ */
+
+#ifndef _JVMTI_AGENT_H_
+#define _JVMTI_AGENT_H_
+
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include "jvmti.h"
+
+#ifdef NDEBUG
+#define DEBUG(str)
+#else // NDEBUG
+#define DEBUG(str)      std::cout << "DEBUG: " << str << std::endl <<
std::flush;
+#endif // NDEBUG
+
+#define REPORT(str)     std::cerr << "ERROR: " << str << std::endl <<
std::flush;
+#define ERR_REPORT(str)                                                 \
+    {                                                                   \
+        std::cerr << "ERROR: " << str << std::endl << std::flush;
      \
+        error = true;                                                   \
+    }
+
+#define CHECK_ERROR()   \
+    if(error) {         \
+        return;         \
+    }
+
+void JNICALL
+agent_callback_ThreadStart(jvmtiEnv* jvmti_env,
+                           JNIEnv* jni_env,
+                           jthread thread);
+
+void JNICALL
+agent_callback_Breakpoint( jvmtiEnv* jvmti_env,
+                           JNIEnv* jni_env,
+                           jthread thread,
+                           jmethodID method,
+                           jlocation location);
+
+void JNICALL 
+agent_callback_SingleStep( jvmtiEnv * jvmti_env,
+                           JNIEnv * jni_env,
+                           jthread thread,
+                           jmethodID method,
+                           jlocation location);
+
+#endif // _JVMTI_AGENT_H_

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/agent.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/popframe.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/popframe.cpp?view=auto&rev=527239
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/popframe.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/popframe.cpp Tue Apr 10 11:28:12
2007
@@ -0,0 +1,360 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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 Pavel Rebriy
+ */
+
+#include "agent.h"
+
+static bool error = false;
+
+static void
+set_test_success( jvmtiEnv* jvmti_env,
+                  JNIEnv* jni_env)
+{
+    CHECK_ERROR();
+
+    DEBUG("Setting test success...");
+    jclass klass = jni_env->FindClass("PopFrame1/PopFrame1");
+    if(!klass) {
+        ERR_REPORT("get class");
+        return;
+    }
+    jfieldID field = jni_env->GetStaticFieldID(klass, "status", "Z");
+    if( !field ) {
+        ERR_REPORT("get 'status' field");
+        return;
+    }
+    jni_env->SetStaticBooleanField(klass, field, JNI_TRUE);
+    return;
+}
+
+static void JNICALL
+agent_function(jvmtiEnv * jvmti_env,
+               JNIEnv * jni_env,
+               void *args)
+{
+    CHECK_ERROR();
+
+    DEBUG("agent: Getting java.lang.Thread ...");
+    jclass klass = jni_env->FindClass("java/lang/Thread");
+    if(!klass) {
+        ERR_REPORT("get java.lang.Thread");
+        return;
+    }
+
+    DEBUG("agent: Getting java.lang.Thread.yield() method...");
+    jmethodID yield_method = jni_env->GetStaticMethodID(klass, "yield", "()V");
+    if(!yield_method) {
+        ERR_REPORT("get java.lang.Thread.yield() method");
+        return;
+    }
+
+    jvmtiError result;
+    int count = 0;
+    bool test = false;
+    jthread test_thread = (jthread)args;
+    while( !test ) {
+        DEBUG("agent: Checking test thread suspend state...");
+        int index = 0;
+        while(true) {
+            jvmtiThreadInfo thread_info;
+            result = jvmti_env->GetThreadInfo(test_thread, &thread_info);
+            if(JVMTI_ERROR_NONE != result) {
+                ERR_REPORT("GetThreadInfo");
+                return;
+            }
+
+            jint state;
+            result = jvmti_env->GetThreadState(test_thread, &state);
+            if(JVMTI_ERROR_NONE != result) {
+                ERR_REPORT("GetThreadInfo");
+                return;
+            }
+            if(state & JVMTI_THREAD_STATE_SUSPENDED) {
+                DEBUG("agent: Test thread is suspended!");
+                break;
+            }
+            jni_env->CallStaticVoidMethod(klass, yield_method, NULL);
+            if( !((++index) % 1000) ) {
+                DEBUG("Stage = " << std::hex << state );
+                DEBUG("agent: Waiting suspension of test thread...");
+            }
+        }
+
+        DEBUG("agent: ----- " << ++count << " PopFrame call -----");
+        result = jvmti_env->PopFrame(test_thread);
+        if(JVMTI_ERROR_NONE != result) {
+            if(JVMTI_ERROR_NO_MORE_FRAMES == result) {
+                DEBUG("agent: PopFrame result is JVMTI_ERROR_NO_MORE_FRAMES!");
+                test = true;
+                break;
+            } else {
+                ERR_REPORT("PopFrame result is " << result);
+                jvmti_env->ResumeThread(test_thread);
+                return;
+            }
+        } else {
+            DEBUG("agent: ...success!");
+        }
+
+        DEBUG("agent: Resume test thread");
+        result = jvmti_env->ResumeThread(test_thread);
+        if (result != JVMTI_ERROR_NONE) {
+            ERR_REPORT("ResumeThread");
+            return;
+        }
+    }
+
+    if(!test || count != 3) {
+        ERR_REPORT("Test failed! - unknown interruption");
+        return;
+    }
+
+    DEBUG("agent: Removing SingleStep event...");
+    result = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE,
+        JVMTI_EVENT_SINGLE_STEP, test_thread);
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("SingleStep: SetEventNotificationMode result is " << result );
+        return;
+    }
+
+    set_test_success( jvmti_env, jni_env );
+   
+    DEBUG("agent: Resume test thread");
+    result = jvmti_env->ResumeThread(test_thread);
+    if (result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("ResumeThread");
+        return;
+    }
+
+    DEBUG("agent: thread is done!");
+    return;
+}
+
+static void
+do_agent_notify(jvmtiEnv* jvmti_env)
+{
+    DEBUG("test: Suspending test thread...");
+    jvmtiError result = jvmti_env->SuspendThread(NULL);
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("SuspendThread result is " << result );
+        return;
+    }
+
+    DEBUG("test: Breakpoint callback is done!");
+    return;
+}
+
+void JNICALL
+agent_callback_Breakpoint( jvmtiEnv* jvmti_env,
+                           JNIEnv* jni_env,
+                           jthread thread,
+                           jmethodID method,
+                           jlocation location)
+{
+    CHECK_ERROR();
+
+    char *name;
+    char *descr;
+    jvmtiError result = jvmti_env->GetMethodName(method, &name, &descr, NULL);
+    if( result != JVMTI_ERROR_NONE
+        || strcmp(name, "third_step") || strcmp(descr, "()V" ) )
+    {
+        return;
+    }
+    jclass klass;
+    result = jvmti_env->GetMethodDeclaringClass(method, &klass);
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("get method class");
+        return;
+    }
+    char *class_name;
+    result = jvmti_env->GetClassSignature(klass, &class_name, NULL);
+    if(result != JVMTI_ERROR_NONE
+        || strcmp(class_name, "LPopFrame1/PopFrame1$1;"))
+    {
+        ERR_REPORT("wrong Breakpoint callback");
+        return;
+    }
+    DEBUG("test: Breakpoint occupied in function PopFrame1.PopFrame1.third_step()");
+
+    DEBUG("test: Clearing breakpoint...");
+    result = jvmti_env->ClearBreakpoint(method, location);
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("clear breakpoint");
+        return;
+    }
+
+    DEBUG("test: Setting SingleStep event...");
+    result = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE,
+        JVMTI_EVENT_SINGLE_STEP, thread);
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("SingleStep: SetEventNotificationMode result is " << result );
+        return;
+    }
+
+    do_agent_notify(jvmti_env);
+
+    DEBUG("test: Breakpoint callback is done!");
+    return;
+}
+
+void JNICALL 
+agent_callback_SingleStep( jvmtiEnv * jvmti_env,
+                           JNIEnv * jni_env,
+                           jthread thread,
+                           jmethodID method,
+                           jlocation location)
+{
+    CHECK_ERROR();
+
+    char *name;
+    char *descr;
+    jvmtiError result = jvmti_env->GetMethodName(method, &name, &descr, NULL);
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("get method name");
+        return;
+    }
+    jclass klass;
+    result = jvmti_env->GetMethodDeclaringClass(method, &klass);
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("get method class");
+        return;
+    }
+    char *class_name;
+    result = jvmti_env->GetClassSignature(klass, &class_name, NULL);
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("get class name");
+        return;
+    }
+    DEBUG("test: SingleStep occupied in function: " << name << descr
+        << ", class: " << class_name);
+
+    do_agent_notify(jvmti_env);
+
+    DEBUG("test: SingleStep callback is done!");
+    return;
+}
+
+void JNICALL
+agent_callback_ThreadStart(jvmtiEnv* jvmti_env,
+                           JNIEnv* jni_env,
+                           jthread start_thread)
+{
+    jvmtiPhase phase;
+    jvmtiError result = jvmti_env->GetPhase(&phase);
+    if(phase != JVMTI_PHASE_LIVE) {
+        return;
+    }
+
+    jvmtiThreadInfo thread_info;
+    result = jvmti_env->GetThreadInfo(start_thread, &thread_info);
+    if(JVMTI_ERROR_NONE != result) {
+        ERR_REPORT("GetThreadInfo");
+        return;
+    }
+    if (strcmp(thread_info.name, "Test thread")) {
+        return;
+    }
+    DEBUG("Tested thread is started!");
+
+    DEBUG("Creating AgentThread...");
+    DEBUG("Getting java.lang.Thread ...");
+    jclass klass = jni_env->FindClass("java/lang/Thread");
+    if(!klass) {
+        ERR_REPORT("get java.lang.Thread");
+        return;
+    }
+
+    DEBUG("Getting java.lang.Thread contructor...");
+    jmethodID method = jni_env->GetMethodID(klass, "<init>", "(Ljava/lang/String;)V");
+    if(!method) {
+        ERR_REPORT("get java.lang.Thread contructor");
+        return;
+    }
+
+    DEBUG("Getting name string...");
+    jstring name = jni_env->NewStringUTF("AgentThread");
+    if(!name) {
+        ERR_REPORT("get name string");
+        return;
+    }
+
+    DEBUG("Creating agent thread...");
+    jthread thread = jni_env->NewObject(klass, method, name);
+    if(!thread) {
+        ERR_REPORT("create thread");
+        return;
+    }
+
+    DEBUG("Creating global reference for test thread...");
+    jobject test_thread = jni_env->NewGlobalRef(start_thread);
+    if(!test_thread) {
+        ERR_REPORT("create thread");
+        return;
+    }
+
+    DEBUG("Getting PopFrame1.PopFrame1$1 ...");
+    klass = jni_env->FindClass("PopFrame1/PopFrame1$1");
+    if(!klass) {
+        ERR_REPORT("get PopFrame1.PopFrame1$1");
+        return;
+    }
+
+    DEBUG("Getting PopFrame1.PopFrame1$1.third_step() method...");
+    method = jni_env->GetMethodID(klass, "third_step", "()V");
+    if(!method) {
+        ERR_REPORT("get PopFrame1.PopFrame1$1.third_step() method");
+        return;
+    }
+
+    DEBUG("Getting line number table...");
+    jvmtiLineNumberEntry *table;
+    jint number;
+    result = jvmti_env->GetLineNumberTable( method, &number, &table );
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("get line number table, error = " << result);
+        return;
+    }
+
+    jlocation location = 0; 
+    for(jint index = 0; index < number - 1; index++) {
+        if( table[index].line_number == 67) {
+            location = table[index].start_location;
+            break;
+        }
+    }
+
+    DEBUG("Setting breakpint...")
+    result = jvmti_env->SetBreakpoint( method, location );
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("set breakpoint");
+        return;
+    }
+
+    DEBUG("Run agent thread...");
+    result = jvmti_env->RunAgentThread(thread, agent_function,
+        (void*)test_thread, JVMTI_THREAD_NORM_PRIORITY);
+    if(result != JVMTI_ERROR_NONE) {
+        ERR_REPORT("agent thread start");
+        return;
+    }
+
+    return;
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/jvmti/PopFrame1/popframe.cpp
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message