harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r794726 [8/15] - in /harmony/enhanced/jdktools/branches/java6/modules/jpda: ./ src/main/native/include/ src/main/native/jdwp/common/agent/commands/ src/main/native/jdwp/common/agent/core/ src/main/native/jdwp/common/generic/ src/main/native...
Date Thu, 16 Jul 2009 15:57:41 GMT
Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.cpp Thu Jul 16 15:57:37 2009
@@ -15,22 +15,16 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.24 $
- */
-// EventDispatcher.cpp
-
 #include "EventDispatcher.h"
 #include "ThreadManager.h"
 #include "OptionParser.h"
 #include "PacketDispatcher.h"
+#include "ExceptionManager.h"
 #include "Log.h"
 
 using namespace jdwp;
 
-EventDispatcher::EventDispatcher(size_t limit) throw() {
+EventDispatcher::EventDispatcher(size_t limit) {
     JDWP_ASSERT(limit > 0);
     m_idCount = 0;
     m_queueMonitor = 0;
@@ -45,67 +39,65 @@
 }
 
 void EventDispatcher::Run(JNIEnv* jni) {
-    JDWP_TRACE_ENTRY("Run(" << jni << ')');
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Run(%p)", jni));
 
-    try {
-        MonitorAutoLock malCM(m_completeMonitor JDWP_FILE_LINE);
-        
-        try {
-            while (!m_stopFlag) {
-                EventComposer *ec;
-            
-                // get next event from queue
-                {
-                    MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
-
-                    while (m_holdFlag || m_eventQueue.empty()) {
-                        m_queueMonitor->Wait();
-                        if (m_stopFlag) break; // break event waiting loop
-                    }
-
-                    if (m_stopFlag) break; // break events handling loop
-
-                    ec = m_eventQueue.front();
-                    m_eventQueue.pop();
-                    m_queueMonitor->NotifyAll();
-                }
-            
-                // send event and suspend thread according to suspend policy
-                SuspendOnEvent(jni, ec);
+    MonitorAutoLock malCM(m_completeMonitor JDWP_FILE_LINE);
+    /*if (GetExceptionManager().GetLastException() != NULL) {
+        AgentException aex = GetExceptionManager().GetLastException();
+        JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "Exception in EventDispatcher synchronization: %s", aex.GetExceptionMessage(jni)));
+        return;
+    }*/
+    
+    while (!m_stopFlag) {
+        EventComposer *ec;
+    
+        // get next event from queue
+        {
+            MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
+
+            while (m_holdFlag || m_eventQueue.empty()) {
+                m_queueMonitor->Wait();
+                if (m_stopFlag) break; // break event waiting loop
             }
+            if (m_stopFlag) break; // break events handling loop
+
+            ec = m_eventQueue.front();
+            m_eventQueue.pop();
+            m_queueMonitor->NotifyAll();
         }
-        catch (const AgentException& e)
-        {
-            JDWP_ERROR("Exception in EventDispatcher thread: "
-                            << e.what() << " [" << e.ErrCode() << "]");
-        
+
+        // send event and suspend thread according to suspend policy
+        int ret = SuspendOnEvent(jni, ec);
+        if (ret != JDWP_ERROR_NONE) {
+            AgentException aex = GetExceptionManager().GetLastException();
+            JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "Exception in EventDispatcher thread: %s", aex.GetExceptionMessage(jni)));
+
             // reset current session
-            JDWP_TRACE_PROG("Run: reset session after exception");
-            GetPacketDispatcher().ResetAll(jni);
+            JDWP_TRACE(LOG_RELEASE, (LOG_PROG_FL, "Run: reset session after exception"));
+            int ret = GetPacketDispatcher().ResetAll(jni);
+            if (ret != JDWP_ERROR_NONE) {
+                AgentException aex = GetExceptionManager().GetLastException();
+                JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "Exception in PacketDispatcher::ResetAll(): %s", aex.GetExceptionMessage(jni)));
+            } 
+            break;
         }
+    }
 
         // release completion monitor and wait forever until VM kills this thread
         // TODO: remove this workaround to prevent from resource leak
 	// This is the old completion mechanism fixed in HARMONY-5019
 //        m_completeMonitor->Wait(0);
-    }
-    catch (const AgentException& e)
-    {
-        // just report an error, cannot do anything else
-        JDWP_ERROR("Exception in EventDispatcher synchronization: "
-                        << e.what() << " [" << e.ErrCode() << "]");
-    }
 }
 
 void JNICALL
 EventDispatcher::StartFunction(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
-    JDWP_TRACE_ENTRY("StartFunction(" << jvmti << ',' << jni << ',' << arg << ')');
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "StartFunction(%p,%p,%p)", jvmti, jni, arg));
 
     (reinterpret_cast<EventDispatcher*>(arg))->Run(jni);
 }
 
-void EventDispatcher::Init(JNIEnv *jni) throw(AgentException) {
-    JDWP_TRACE_ENTRY("Init(" << jni << ')');
+void EventDispatcher::Init(JNIEnv *jni) {
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Init(%p)", jni));
 
     m_queueMonitor = new AgentMonitor("_jdwp_EventDispatcher_queueMonitor");
     m_waitMonitor = new AgentMonitor("_jdwp_EventDispatcher_waitMonitor");
@@ -115,15 +107,20 @@
     m_holdFlag = true;
 }
 
-void EventDispatcher::Start(JNIEnv *jni) throw(AgentException) {
-    JDWP_TRACE_ENTRY("Start(" << jni << ')');
+int EventDispatcher::Start(JNIEnv *jni) {
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Start(%p)", jni));
 
-    m_threadObject = jni->NewGlobalRef(GetThreadManager().RunAgentThread(jni, StartFunction, this,
-        JVMTI_THREAD_MAX_PRIORITY, "_jdwp_EventDispatcher"));
+    jthread thread = GetThreadManager().RunAgentThread(jni, StartFunction, this,
+        JVMTI_THREAD_MAX_PRIORITY, "_jdwp_EventDispatcher");
+    if (thread == 0) {
+        return JDWP_ERROR_INTERNAL;
+    }
+    m_threadObject = jni->NewGlobalRef(thread);
+    return JDWP_ERROR_NONE;
 }
 
-void EventDispatcher::Reset(JNIEnv *jni) throw(AgentException) {
-    JDWP_TRACE_ENTRY("Reset(" << jni << ')');
+void EventDispatcher::Reset(JNIEnv *jni) {
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Reset(%p)", jni));
 
     m_resetFlag = true;
 
@@ -134,7 +131,7 @@
         while(!m_eventQueue.empty()) {
             EventComposer *ec = m_eventQueue.front();
             m_eventQueue.pop();
-            JDWP_TRACE_EVENT("Reset -- delete event set: packet=" << ec);
+            JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "Reset -- delete event set: packet=%p", ec));
             ec->Reset(jni);
             delete ec;
         }
@@ -155,8 +152,8 @@
     }
 }
 
-void EventDispatcher::Stop(JNIEnv *jni) throw(AgentException) {
-    JDWP_TRACE_ENTRY("Stop(" << jni << ')');
+void EventDispatcher::Stop(JNIEnv *jni) {
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Stop(%p)", jni));
 
     // let thread loop to finish
     {
@@ -177,8 +174,8 @@
     m_threadObject = NULL;
 }
 
-void EventDispatcher::Clean(JNIEnv *jni) throw(AgentException) {
-    JDWP_TRACE_ENTRY("Clean(" << jni << ')');
+void EventDispatcher::Clean(JNIEnv *jni) {
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Clean(%p)", jni));
     
     // The following code is just a workaround for known problem
     // in reset and clean-up procedure to release threads which
@@ -199,8 +196,9 @@
     }
 
     // delete monitors
-    
-    if (m_queueMonitor != 0) {
+
+    /* Commented out as a workaround for shutdown crash - TODO apply correct behaviour to free these locks */
+    /*if (m_queueMonitor != 0) {
         delete m_queueMonitor;
         m_queueMonitor = 0;
     }
@@ -211,7 +209,7 @@
     if (m_invokeMonitor != 0){
         delete m_invokeMonitor;
         m_invokeMonitor = 0;
-    }
+    }*/
 
     // do not delete m_completeMonitor because thread is waiting on it
     // TODO: remove this workaround to prevent from resource leak
@@ -226,84 +224,86 @@
     m_idCount = 0;
 }
 
-void EventDispatcher::HoldEvents() throw(AgentException) {
-    JDWP_TRACE_ENTRY("HoldEvents()");
+void EventDispatcher::HoldEvents() {
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "HoldEvents()"));
 
     MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
     m_holdFlag = true;
 }
 
-void EventDispatcher::ReleaseEvents() throw(AgentException) {
-    JDWP_TRACE_ENTRY("ReleaseEvents()");
+void EventDispatcher::ReleaseEvents() {
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "ReleaseEvents()"));
 
     MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
     m_holdFlag = false;
     m_queueMonitor->NotifyAll();
 }
 
-void EventDispatcher::NewSession() throw(AgentException) {
-    JDWP_TRACE_ENTRY("NewSession()");
+void EventDispatcher::NewSession() {
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "NewSession()"));
 
     m_resetFlag = false;
     m_holdFlag = true;
 }
 
-void EventDispatcher::PostInvokeSuspend(JNIEnv *jni, SpecialAsyncCommandHandler* handler) 
-    throw(AgentException) 
+int EventDispatcher::PostInvokeSuspend(JNIEnv *jni, SpecialAsyncCommandHandler* handler) 
+    
 {
-    JDWP_TRACE_ENTRY("PostInvokeSuspend(" << jni << ',' << handler << ')');
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "PostInvokeSuspend(%p,%p)", jni, handler));
 
     MonitorAutoLock lock(m_invokeMonitor JDWP_FILE_LINE);
     jthread thread = handler->GetThread();
 
+    int ret;
     char* threadName = 0;
 #ifndef NDEBUG
         if (JDWP_TRACE_ENABLED(LOG_KIND_EVENT)) {
             jvmtiError err;
             jvmtiThreadInfo threadInfo;
-            JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
+            JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
             threadName = threadInfo.name;
         }
 #endif // NDEBUG
     JvmtiAutoFree af(threadName);
 
     // wait for thread to complete method invocation and ready for suspension
-    JDWP_TRACE_EVENT("PostInvokeSuspend -- wait for method invoked: thread=" << thread 
-            << ", name=" << JDWP_CHECK_NULL(threadName));
+    JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "PostInvokeSuspend -- wait for method invoked: thread=%p, name=%s", thread, JDWP_CHECK_NULL(threadName)));
     while (!handler->IsInvoked()) {
         m_invokeMonitor->Wait();
         if (m_resetFlag) {
-            return;
+            return JDWP_ERROR_NONE;
         }
     }
 
     // suspend single thread or all threads accodring to invocation options
     if ((handler->GetOptions() & JDWP_INVOKE_SINGLE_THREADED) == 0) {
-        JDWP_TRACE_EVENT("PostInvokeSuspend -- suspend all after method invoke: thread=" << thread 
-                << ", name=" << JDWP_CHECK_NULL(threadName));
-        GetThreadManager().SuspendAll(jni, handler->GetThread());
+        JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "PostInvokeSuspend -- suspend all after method invoke: thread=%p, name=%s", thread, JDWP_CHECK_NULL(threadName)));
+        ret = GetThreadManager().SuspendAll(jni, handler->GetThread());
+        JDWP_CHECK_RETURN(ret);
     } else {
-        JDWP_TRACE_EVENT("PostInvokeSuspend -- suspend after method invoke: thread=" << thread 
-                << ", name=" << JDWP_CHECK_NULL(threadName));
-        GetThreadManager().Suspend(jni, handler->GetThread(), true);
+        JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "PostInvokeSuspend -- suspend after method invoke: thread=%p, name=%s", thread, JDWP_CHECK_NULL(threadName)));
+        ret = GetThreadManager().Suspend(jni, handler->GetThread(), true);
+        JDWP_CHECK_RETURN(ret);
     }
 
     // release thread after suspension
-    JDWP_TRACE_EVENT("SuspendOnEvent -- release after method invoke: thread=" << thread  
-                << ", name=" << JDWP_CHECK_NULL(threadName));
+    JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "SuspendOnEvent -- release after method invoke: thread=%p, name=%s", thread, JDWP_CHECK_NULL(threadName)));
     handler->SetReleased(true);
     m_invokeMonitor->NotifyAll();
+
+    return JDWP_ERROR_NONE;
 }
 
-void EventDispatcher::SuspendOnEvent(JNIEnv* jni, EventComposer *ec)
-    throw(AgentException)
+int EventDispatcher::SuspendOnEvent(JNIEnv* jni, EventComposer *ec)
+   
 {
-    JDWP_TRACE_EVENT("SuspendOnEvent -- send event set: id=" << ec->event.GetId()
-        << ", policy=" << ec->GetSuspendPolicy());
+    JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "SuspendOnEvent -- send event set: id=%d, policy=%d", ec->event.GetId(), ec->GetSuspendPolicy()));
+    int ret = 0;
     if (ec->GetSuspendPolicy() == JDWP_SUSPEND_NONE && !ec->IsAutoDeathEvent()) {
         // thread is not waiting for suspension
-        ec->WriteEvent(jni);
-        JDWP_TRACE_EVENT("SuspendOnEvent -- delete event set: packet=" << ec);
+        ret = ec->WriteEvent(jni);
+        JDWP_CHECK_RETURN(ret);
+        JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "SuspendOnEvent -- delete event set: packet=%p", ec));
         ec->Reset(jni);
         delete ec;
     } else {
@@ -315,49 +315,51 @@
         if (JDWP_TRACE_ENABLED(LOG_KIND_EVENT)) {
             jvmtiError err;
             jvmtiThreadInfo threadInfo;
-            JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
+            JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
             threadName = threadInfo.name;
         }
 #endif // NDEBUG
         JvmtiAutoFree af(threadName);
 
         // wait for thread to reach suspension point
-        JDWP_TRACE_EVENT("SuspendOnEvent -- wait for thread on event: thread=" << thread 
-                << ", name=" << JDWP_CHECK_NULL(threadName));
+        JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "SuspendOnEvent -- wait for thread on event: thread=%p, name=%s", thread, JDWP_CHECK_NULL(threadName)));
+
         while (!ec->IsWaiting()) {
             m_waitMonitor->Wait();
             if (m_resetFlag) {
-                return;
+                return JDWP_ERROR_NONE;
             }
         }
 
         // suspend corresponding threads if necessary
         if (ec->GetSuspendPolicy() == JDWP_SUSPEND_ALL) {
-            JDWP_TRACE_EVENT("SuspendOnEvent -- suspend all threads on event: thread=" << thread 
-                    << ", name=" << JDWP_CHECK_NULL(threadName));
-            GetThreadManager().SuspendAll(jni, thread);
+            JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "SuspendOnEvent -- suspend all threads on event: thread=%p, name=%s", thread, JDWP_CHECK_NULL(threadName)));
+            ret = GetThreadManager().SuspendAll(jni, thread);
+            JDWP_CHECK_RETURN(ret);
         } else if (ec->GetSuspendPolicy() == JDWP_SUSPEND_EVENT_THREAD) {
-            JDWP_TRACE_EVENT("SuspendOnEvent -- suspend thread on event: thread=" << thread 
-                    << ", name=" << JDWP_CHECK_NULL(threadName));
+            JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "SuspendOnEvent -- suspend thread on event: thread=%p, name=%s", thread, JDWP_CHECK_NULL(threadName)));
             JDWP_ASSERT(thread != 0);
-            GetThreadManager().Suspend(jni, thread, true);
+            ret = GetThreadManager().Suspend(jni, thread, true);
+            JDWP_CHECK_RETURN(ret);
         }
 
         // send event packet
-        ec->WriteEvent(jni);
+        ret = ec->WriteEvent(jni);
+        JDWP_CHECK_RETURN(ret);
 
         // release thread on suspension point
-        JDWP_TRACE_EVENT("SuspendOnEvent -- release thread on event: thread=" << thread 
-                << ", name=" << JDWP_CHECK_NULL(threadName));
+        JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "SuspendOnEvent -- release thread on event: thread=%p, name=%s", thread, JDWP_CHECK_NULL(threadName)));
         ec->SetReleased(true);
         m_waitMonitor->NotifyAll();
     }
+
+    return JDWP_ERROR_NONE;
 }
 
 void EventDispatcher::PostEventSet(JNIEnv *jni, EventComposer *ec, jdwpEventKind eventKind)
-    throw(AgentException)
+   
 {
-    JDWP_TRACE_ENTRY("PostEventSet(" << jni << ',' << ec << ',' << eventKind << ')');
+    JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "PostEventSet(%p,%p,%d)", jni, ec, eventKind));
 
     if (m_stopFlag) {
         return;
@@ -369,11 +371,10 @@
     // put event packet into queue
     {
         MonitorAutoLock lock(m_queueMonitor JDWP_FILE_LINE);
-        while (m_eventQueue.size() > m_queueLimit) {
+        while (m_eventQueue.size() > (jint)m_queueLimit) {
             m_queueMonitor->Wait();
             if (m_resetFlag) {
-                JDWP_TRACE_EVENT("PostEventSet -- delete event set: packet=" << ec 
-                    << ", eventKind=" << eventKind);
+                JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "PostEventSet -- delete event set: packet=%p, evenKind=%d", ec, eventKind));
                 ec->Reset(jni);
                 delete ec;
                 return;
@@ -393,7 +394,7 @@
         if (JDWP_TRACE_ENABLED(LOG_KIND_EVENT)) {
             jvmtiError err;
             jvmtiThreadInfo threadInfo;
-            JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
+            JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
             threadName = threadInfo.name;
         }
 #endif // NDEBUG
@@ -402,8 +403,7 @@
         // wait on suspension point
         {
             MonitorAutoLock lock(m_waitMonitor JDWP_FILE_LINE);
-            JDWP_TRACE_EVENT("PostEventSet -- wait for release on event: thread=" << thread
-                << ", name=" << JDWP_CHECK_NULL(threadName) << ", eventKind=" << eventKind);
+            JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "PostEventSet -- wait for release on event: thread=%p, name=%s, eventKind=%d", thread, JDWP_CHECK_NULL(threadName), eventKind));
 
             // notify that thread is waiting on suspension point
             ec->SetWaiting(true);
@@ -412,28 +412,36 @@
             // wait for thread to be released after suspension
             while (!ec->IsReleased()) {
                 m_waitMonitor->Wait();
-                if (m_resetFlag) {
+                if (m_resetFlag || m_stopFlag) {
                     return;
                 }
             }
 
-            JDWP_TRACE_EVENT("PostEventSet -- released on event: thread=" << thread
-                << ", name=" << JDWP_CHECK_NULL(threadName) << ", eventKind=" << eventKind);
+            JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "PostEventSet -- released on event: thread=%p, name=%s, eventKind=%d", thread, JDWP_CHECK_NULL(threadName), eventKind));
         }
-        
+       
+	if (GetThreadManager().IsSuspended(thread)) {
+	    jvmtiError error;
+	    JVMTI_TRACE(LOG_DEBUG, error, GetJvmtiEnv()->ResumeThread(thread));
+	    if (error == JVMTI_ERROR_NONE) {
+		JVMTI_TRACE(LOG_DEBUG, error, GetJvmtiEnv()->SuspendThread(thread));
+	    }
+            JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "PostEventSet -- Running suspended thread: thread=%p, name=%s, eventKind=%d", thread, threadName, eventKind));
+	}
+
         // execute all registered InvokeMethod handlers sequentially
         if (thread != 0 && suspendPolicy != JDWP_SUSPEND_NONE) {
             ExecuteInvokeMethodHandlers(jni, thread);
         }
         
         // delete event packet
-        JDWP_TRACE_EVENT("PostEventSet -- delete event set: packet=" << ec);
+        JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "PostEventSet -- delete event set: packet=%p", ec));
         ec->Reset(jni);
         delete ec;
     }
 }
 
-void EventDispatcher::ExecuteInvokeMethodHandlers(JNIEnv *jni, jthread thread) throw(AgentException)
+void EventDispatcher::ExecuteInvokeMethodHandlers(JNIEnv *jni, jthread thread)
 {
     // if reset process, don't invoke handlers
     if (m_resetFlag) {
@@ -445,7 +453,7 @@
     jvmtiError err;
     if (JDWP_TRACE_ENABLED(LOG_KIND_EVENT)) {
         jvmtiThreadInfo threadInfo;
-        JVMTI_TRACE(err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
+        JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->GetThreadInfo(thread, &threadInfo));
         threadName = threadInfo.name;
     }
 #endif // NDEBUG
@@ -458,8 +466,7 @@
         while ((handler =
             GetThreadManager().FindInvokeHandler(jni, thread)) != 0)
         {
-            JDWP_TRACE_EVENT("ExecuteInvokeMethodHandlers -- invoke method: thread=" << thread
-                << ", name=" << JDWP_CHECK_NULL(threadName) << ", handler=" << handler);
+            JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "ExecuteInvokeMethodHandlers -- invoke method: thread=%p, threadName=%s, handler=%p", thread, JDWP_CHECK_NULL(threadName), handler));
             handler->ExecuteDeferredInvoke(jni);
 
             MonitorAutoLock invokeMonitorLock(m_invokeMonitor JDWP_FILE_LINE);
@@ -469,16 +476,24 @@
             m_invokeMonitor->NotifyAll();
 
             // wait on suspension point after method invocation
-            JDWP_TRACE_EVENT("ExecuteInvokeMethodHandlers -- wait for released on event: thread=" << thread
-                << ", name=" << JDWP_CHECK_NULL(threadName) << ", handler=" << handler);
+            JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "ExecuteInvokeMethodHandlers -- wait for released on event: thread=%p, threadName=%s, handler=%p", thread, JDWP_CHECK_NULL(threadName), handler));
             while (!handler->IsReleased()) {
                 m_invokeMonitor->Wait();
                 if (m_resetFlag) {
                     return;
                 }
             }
-            JDWP_TRACE_EVENT("ExecuteInvokeMethodHandlers -- released on event: thread=" << thread 
-                << ", name=" << JDWP_CHECK_NULL(threadName) << ", handler=" << handler);
+
+	    if (GetThreadManager().IsSuspended(thread)) {
+		jvmtiError error;
+		JVMTI_TRACE(LOG_DEBUG, error, GetJvmtiEnv()->ResumeThread(thread));
+		if (error == JVMTI_ERROR_NONE) {
+		    JVMTI_TRACE(LOG_DEBUG, error, GetJvmtiEnv()->SuspendThread(thread));
+		}
+                JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "ExecuteInvokeMethodHandlers -- Running suspended thread: thread=%p, name=%s", thread, threadName));
+	    }
+
+            JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "ExecuteInvokeMethodHandlers -- released on event: thread=%p, threadName=%s, handler=%p", thread, JDWP_CHECK_NULL(threadName), handler));
         }
     }
 }

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/EventDispatcher.h Thu Jul 16 15:57:37 2009
@@ -15,12 +15,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.11.2.1 $
- */
-
 /**
  * @file
  * EventDispatcher.h
@@ -32,21 +26,18 @@
 #ifndef _EVENT_DISPATCHER_H_
 #define _EVENT_DISPATCHER_H_
 
-#include <queue>
-
+#include "Util.h"
 #include "jni.h"
 #include "jvmti.h"
 #include "jdwp.h"
 
 #include "AgentBase.h"
 #include "AgentMonitor.h"
-#include "AgentAllocator.h"
 #include "PacketParser.h"
 #include "CommandHandler.h"
 
 
 namespace jdwp {
-
     /**
      * The given class provides a separate thread that dispatches all event packets, 
      * suspends threads on events and performs deferred method invocation.
@@ -61,13 +52,13 @@
          * 
          * @param limit - maximum even queue length
          */
-        EventDispatcher(size_t limit = 1024) throw();
+        EventDispatcher(size_t limit = 1024);
 
         /**
          * A destructor.
          * Destroys the given instance.
          */
-        ~EventDispatcher() throw() {}
+        ~EventDispatcher() {}
 
         /**
          * Initializes this events before starting the thread.
@@ -76,7 +67,7 @@
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void Init(JNIEnv *jni) throw(AgentException);
+        void Init(JNIEnv *jni);
 
         /**
          * Starts the given thread.
@@ -85,7 +76,7 @@
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void Start(JNIEnv *jni) throw(AgentException);
+        int Start(JNIEnv *jni);
 
         /**
          * Resets all data.
@@ -94,7 +85,7 @@
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void Reset(JNIEnv *jni) throw(AgentException);
+        void Reset(JNIEnv *jni);
 
         /**
          * Stops the given thread.
@@ -103,7 +94,7 @@
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void Stop(JNIEnv *jni) throw(AgentException);
+        void Stop(JNIEnv *jni);
 
         /**
          * Cleans all data after thread completion.
@@ -112,33 +103,33 @@
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void Clean(JNIEnv *jni) throw(AgentException);
+        void Clean(JNIEnv *jni);
 
         /**
          * Turns on the flag to hold all events.
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void HoldEvents() throw(AgentException);
+        void HoldEvents();
 
         /**
          * Turns off the flag to hold all events.
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void ReleaseEvents() throw(AgentException);
+        void ReleaseEvents();
 
         /**
          * Informs that new session started.
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void NewSession() throw(AgentException);
+        void NewSession();
 
         /**
          * Generates new ID for the event packet.
          */
-        jint NewId() throw() { return m_idCount++; }
+        jint NewId() { return m_idCount++; }
 
         /**
          * Sends the event packet and suspends thread(s) according to suspend 
@@ -150,8 +141,7 @@
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void PostEventSet(JNIEnv *jni, EventComposer *ec, jdwpEventKind eventKind)
-            throw(AgentException);
+        void PostEventSet(JNIEnv *jni, EventComposer *ec, jdwpEventKind eventKind);
 
         /**
          * Suspends thread(s) after method invocation according to invocation 
@@ -162,8 +152,7 @@
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void PostInvokeSuspend(JNIEnv *jni, SpecialAsyncCommandHandler* handler)
-            throw(AgentException);
+        int PostInvokeSuspend(JNIEnv *jni, SpecialAsyncCommandHandler* handler);
 
         /**
          * Executes all handlers of methods that should be invoked on the 
@@ -174,8 +163,7 @@
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void ExecuteInvokeMethodHandlers(JNIEnv *jni, jthread thread) 
-            throw(AgentException);
+        void ExecuteInvokeMethodHandlers(JNIEnv *jni, jthread thread);
 
     protected:
 
@@ -205,13 +193,14 @@
          *
          * @exception If any error occurs, <code>AgentException</code> is thrown.
          */
-        void SuspendOnEvent(JNIEnv* jni, EventComposer *ec) throw(AgentException);
+        int SuspendOnEvent(JNIEnv* jni, EventComposer *ec);
 
         /**
          * Event queue type.
          */
-        typedef queue<EventComposer*,
-            deque<EventComposer*, AgentAllocator<EventComposer*> > > EventQueue;
+        //typedef queue<EventComposer*,
+        //    deque<EventComposer*, AgentAllocator<EventComposer*> > > EventQueue;
+        typedef JDWPQueue EventQueue;
 
         /**
          * Event queue with event packets to be sent.

Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.cpp?rev=794726&view=auto
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.cpp (added)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.cpp Thu Jul 16 15:57:37 2009
@@ -0,0 +1,139 @@
+/*
+ * 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.
+ */
+
+#ifndef USING_VMI
+#define USING_VMI
+#endif
+
+#include "ExceptionManager.h"
+
+using namespace jdwp;
+
+static inline ThreadId_t _GetCurrentThreadId(JavaVM *jvm)
+{
+    ThreadId_t tid;
+#ifdef HY_NO_THR
+    THREAD_ACCESS_FROM_JAVAVM(jvm);
+#endif /* HY_NO_THR */
+    hythread_attach(&tid);
+    return tid;
+} // GetCurrentThreadId()
+
+
+static inline bool ThreadId_equal(ThreadId_t treadId1, ThreadId_t treadId2)
+{
+    return (treadId1 == treadId2);
+} // ThreadId_equal()
+
+void ExceptionManager::Init(JNIEnv *jni) {
+    jni->GetJavaVM(&m_jvm);
+    m_monitor = new AgentMonitor("_jdwp_exception_monitor");
+}
+
+ExceptionManager::ExceptionManager() {
+    m_context = 0;
+}
+
+void ExceptionManager::Clean() {
+    exception_context* context = m_context;
+    while (context != 0) {
+        m_context = context->next_context;
+        free(context);
+        context = m_context;
+    }
+}
+
+exception_context* ExceptionManager::GetCurrentContext(ThreadId_t tid) {
+    
+    exception_context* context = m_context;
+    exception_context* pre_context = 0;
+ 
+    while (context != 0) {
+        // remove context contains no exception
+        while (context->lastException == NULL) {
+            if (pre_context == 0) {
+                m_context = context->next_context;
+                free(context);
+
+                context = m_context;
+            } else {
+                pre_context->next_context = context->next_context;
+                free(context);
+                context = pre_context->next_context;
+            }
+
+            if (context == 0) {
+                return 0;
+            }
+        }
+
+        if (ThreadId_equal(tid, context->id)) {
+            return context;
+        }
+
+        pre_context = context;
+        context = context->next_context;
+    }
+
+    return 0;
+}
+
+exception_context* ExceptionManager::AddNewContext(ThreadId_t tid) {
+    exception_context* context = (exception_context*) malloc(sizeof(exception_context));
+    context->id = tid;
+    context->next_context = m_context;
+    context->lastException = NULL;
+    m_context = context;
+    return m_context;
+}
+
+AgentException* ExceptionManager::Clone(AgentException* ex) {
+    AgentException* e = new AgentException(*ex);
+    return e;
+}
+
+
+void ExceptionManager::SetException(AgentException& ex) {
+    ThreadId_t tid = _GetCurrentThreadId(m_jvm);
+    MonitorAutoLock lock(m_monitor JDWP_FILE_LINE);
+
+    exception_context* context = GetCurrentContext(tid);
+    if (context == 0) {
+        context = AddNewContext(tid);
+    }
+
+    if (!context->lastException) {
+        context->lastException = Clone(&ex);
+    }
+}
+
+AgentException ExceptionManager::GetLastException() {
+    ThreadId_t tid = _GetCurrentThreadId(m_jvm);
+    MonitorAutoLock lock(m_monitor JDWP_FILE_LINE);
+
+    exception_context* context = GetCurrentContext(tid);
+    AgentException* aex;
+    if (context == 0 || context->lastException == 0) {
+        aex = new AgentException(JDWP_ERROR_NONE);
+    } else {    
+        aex = context->lastException;
+        context->lastException = NULL;
+    }
+    return *aex;
+}
+

Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.h?rev=794726&view=auto
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.h (added)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.h Thu Jul 16 15:57:37 2009
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+#ifndef _EXCEPTION_MANAGER_H
+#define _EXCEPTION_MANAGER_H
+
+#include <setjmp.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "AgentBase.h"
+#include "AgentException.h"
+#include "AgentMonitor.h"
+#include "vmi.h"
+#include "hythread.h"
+#include "hyport.h"
+#include "jni.h"
+#include "jvmti.h"
+
+#define JDWP_SET_EXCEPTION(ex) AgentBase::GetExceptionManager().SetException(ex)
+
+#define JDWP_CHECK_RETURN(value) if (value != JDWP_ERROR_NONE) { \
+                                    return value; \
+                                 }
+
+namespace jdwp {
+
+    typedef hythread_t ThreadId_t;
+
+    struct exception_context {
+        ThreadId_t id;
+        AgentException* lastException;
+        struct exception_context* next_context;
+    };
+
+    typedef struct exception_context exception_context;
+
+
+    class ExceptionManager
+    {
+    public:
+        ExceptionManager();
+
+        /**
+         * A destructor.
+         */
+        ~ExceptionManager();
+
+        void Init(JNIEnv *jni);
+        void Clean();
+
+        void SetException(AgentException& ex);
+        AgentException GetLastException();
+
+        inline void* operator new(size_t size) {
+            return malloc(size);
+        }
+
+        inline void operator delete(void* ptr) {
+            free(ptr);
+        }
+
+    private:
+        exception_context* GetCurrentContext(ThreadId_t tid);
+        exception_context* AddNewContext(ThreadId_t tid);
+        AgentException* Clone(AgentException* ex);
+        exception_context* m_context;
+
+        JavaVM *m_jvm;
+        AgentMonitor* m_monitor;
+    };
+};
+#endif  // _EXCEPTION_MANAGER_H

Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Log.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Log.h?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Log.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Log.h Thu Jul 16 15:57:37 2009
@@ -17,138 +17,101 @@
  */
 
 /**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.9.2.1 $
- */
-#ifndef _LOG_H_
-#define _LOG_H_
-
-#include <sstream>
-#include "LogManager.h"
-
-/**
  * @file
  * Log.h
  *
  * Macros in the given file provide functionality for tracing
- * program execution in a debug mode except INFO and ERROR,
- * which work in a release mode as well as in a debug one.
+ * program execution in a debug mode except INFO, SIMPLE and 
+ * ERROR, which work in a release mode as well as in a debug 
+ * one. 
  */
 
+#ifndef _LOG_H_
+#define _LOG_H_
+
+#include <stdarg.h>
+#include "LogManager.h"
+
 /**
  * Safe null-checking method for passing a string as a parameter.
  */
 #define JDWP_CHECK_NULL(str) ( (str)==0 ? "(null)" : (str) )
 
 /**
- * Traces messages using the corresponding method of a log manager.
+ * Macro definition for assertion checking in JDWP agent code.
  */
-#define JDWP_MESSAGE(method, message) { \
-    std::ostringstream _oss; \
-    _oss << message; \
-    AgentBase::GetLogManager().method(_oss.str(), __FILE__, __LINE__); \
-}
+#ifdef NDEBUG
+ #define JDWP_ASSERT(assert)
+#else // !NDEBUG
+ #define JDWP_ASSERT(assert) { \
+    if (!(assert)) { \
+        JDWP_TRACE(LOG_DEBUG, (LOG_ERROR_FL, "assert \"%s\" failed", #assert)); \
+        ::exit(1); \
+    } \
+ }
+#endif // !NDEBUG
 
-/**
- * Traces INFO kind of the messages.
- */
-#define JDWP_INFO(message) JDWP_MESSAGE(Info, message)
 
 /**
- * Traces ERROR kind of the messages.
+ * Defines to indicate the current levels of tracing available. 
+ *  LOG_RELEASE indicates tracepoints that will be executed when
+ * building in both release and debug configuration. 
+ *  LOG_DEBUG indicates tracepoints that will be executed when 
+ * building in debug configuration only. 
  */
-#define JDWP_ERROR(message) JDWP_MESSAGE(Error, message)
+#define LOG_RELEASE JDWP_TRACE_RELEASE
+#define LOG_DEBUG JDWP_TRACE_DEBUG
 
 /**
- * Traces messages of a specific kind. The macro is empty in a release mode.
+ * Macros to check if the specified kind of tracing is enabled.
+ *  
+ * 2 versions - one takes just the kind of tracing, the other 
+ * can take a variable argument list as specified to the 
+ * JDWP_TRACE macro.
  */
-#define JDWP_TRACE(kind, message) JDWP_TRACE_EX(kind, __FILE__, __LINE__, message)
-
-#define JDWP_TRACE_CMD(message) JDWP_TRACE(LOG_KIND_CMD, message)
-#define JDWP_TRACE_EVENT(message) JDWP_TRACE(LOG_KIND_EVENT, message)
-#define JDWP_TRACE_PACKET(message) JDWP_TRACE(LOG_KIND_PACKET, message)
-#define JDWP_TRACE_THREAD(message) JDWP_TRACE(LOG_KIND_THREAD, message)
-#define JDWP_TRACE_DATA(message) JDWP_TRACE(LOG_KIND_DATA, message)
-#define JDWP_TRACE_MEMORY(message) JDWP_TRACE(LOG_KIND_MEMORY, message)
-#define JDWP_TRACE_MAP(message) JDWP_TRACE(LOG_KIND_MAP, message)
-#define JDWP_TRACE_JVMTI(message) JDWP_TRACE(LOG_KIND_JVMTI, message)
-#define JDWP_TRACE_FUNC(message) JDWP_TRACE(LOG_KIND_FUNC, message)
-#define JDWP_TRACE_MON(message) JDWP_TRACE(LOG_KIND_MON, message)
-#define JDWP_TRACE_UTIL(message) JDWP_TRACE(LOG_KIND_UTIL, message)
-#define JDWP_TRACE_PROG(message) JDWP_TRACE(LOG_KIND_PROG, message)
+ #define JDWP_TRACE_ENABLED(kind) AgentBase::GetLogManager().TraceEnabled(kind, __FILE__, __LINE__, "")
+ #define JDWP_TRACE_ENABLED_VAARGS(args) AgentBase::GetLogManager().TraceEnabled args
 
 /**
- * Traces the JVMTI kind of the messages.
+ * Trace JVMTI calls - has format 
+ *  JVMTI_TRACE(level, err, function_call)
+ * where 
+ *  level - the tracing level, either LOG_RELEASE or LOG_DEBUG
+ *  err - the variable to store the return code in
+ *  function_call - the function call to execute
  */
-#define JVMTI_TRACE(err, function_call) { \
-    JDWP_TRACE_JVMTI(">> " #function_call); \
+#define JVMTI_TRACE(level, err, function_call) { \
+    JDWP_TRACE(level, (LOG_JVMTI_FL, ">> %s", #function_call)); \
     err = function_call; \
-    JDWP_TRACE_JVMTI("<< " #function_call "=" << err); \
+    JDWP_TRACE(level, (LOG_JVMTI_FL, "<< %s=%d", #function_call, err)); \
 }
 
 /**
- * Prints the message and terminates the program execution.
- */
-#define JDWP_DIE(message) { \
-    JDWP_ERROR(message); \
-    exit(1); \
-}
+* Macros providing trace for JDWP agent code 
+*  
+* Tracepoints are of the format: 
+*  JDWP_TRACE(level, (kind, file, line, format, tokens));
+* where 
+*  level - either LOG_RELEASE or LOG_DEBUG
+*  kind - the type of trace, e.g. LOG_KIND_EVENT
+*  file - the file name
+*  line - the line number
+*  format - the format string, e.g. "Hello %s"
+*  tokens - the tokens to be parsed into the format string,
+*           e.g."World"
+*/
+#define _JDWP_TRACE(args) if (JDWP_TRACE_ENABLED_VAARGS(args)) AgentBase::GetLogManager().Trace args
+#define _JDWP_TRACE_ENTRY(args) JdwpTraceEntry _tre args
 
 #ifdef NDEBUG
+#define JDWP_TRACE_DEBUG(func, args)
+#else
+#define JDWP_TRACE_DEBUG(func, args) func(args)
+#endif
+#define JDWP_TRACE_RELEASE(func, args) func(args)
 
-/**
- * The given macros are empty in a release mode.
- */
-#define JDWP_LOG(message)
-#define JDWP_TRACE_EX(kind, file, line, message)
-#define JDWP_TRACE_ENTRY(message)
-#define JDWP_ASSERT(assert)
-#define JDWP_TRACE_ENABLED(kind) false
-
-#define JDWP_FILE_LINE
-#define JDWP_FILE_LINE_PAR
-#define JDWP_FILE_LINE_INI
-#define JDWP_FILE_LINE_MPAR
-#define JDWP_FILE_LINE_DECL
-
-#else // !NDEBUG
-
-/**
- * Traces LOG kind of the messages.
- */
-#define JDWP_LOG(message) JDWP_MESSAGE(Log, message)
-
-/**
- * Traces messages of a specific kind.
- */
-#define JDWP_TRACE_EX(kind, file, line, message){ \
-    std::ostringstream _oss; \
-    _oss << message; \
-    AgentBase::GetLogManager().Trace(_oss.str(), file, line, kind); \
-}
-
-/**
- * Traces the function kind of the messages.
- */
-#define JDWP_TRACE_ENTRY(message) \
-    std::ostringstream _ose; \
-    _ose << message; \
-    JdwpTraceEntry _tre(_ose, __FILE__, __LINE__, LOG_KIND_FUNC);
-
-/**
- * Verifies the expression and terminates the program execution, if it
- * is <code>FALSE</code>.
- */
-#define JDWP_ASSERT(assert) { \
-    if (!(assert)) { \
-        JDWP_DIE("assert \"" #assert "\" failed"); \
-    } \
-}
-
-/**
- * Checks whether a specific kind of messages is enabled for logging.
- */
-#define JDWP_TRACE_ENABLED(kind) AgentBase::GetLogManager().TraceEnabled(__FILE__, __LINE__, kind)
+#define JDWP_TRACE(level, args) level(_JDWP_TRACE, args)
+#define JDWP_TRACE_ENTRY(level, args) level(_JDWP_TRACE_ENTRY, args)
 
 /**
  * The following macros provide placement for file and line parameters in a debug mode1.
@@ -159,6 +122,27 @@
 #define JDWP_FILE_LINE_MPAR , m_file, m_line
 #define JDWP_FILE_LINE_DECL const char* m_file; int m_line;
 
-#endif // NDEBUG
+/**
+ * Utility defines for kind, file, line in the JDWP_TRACE macros 
+ * above.
+ */
+#define LOG_CMD_FL LOG_KIND_CMD, __FILE__, __LINE__
+#define LOG_EVENT_FL LOG_KIND_EVENT, __FILE__, __LINE__
+#define LOG_PACKET_FL LOG_KIND_PACKET, __FILE__, __LINE__
+#define LOG_THREAD_FL LOG_KIND_THREAD, __FILE__, __LINE__
+#define LOG_DATA_FL LOG_KIND_DATA, __FILE__, __LINE__
+#define LOG_MEMORY_FL LOG_KIND_MEMORY, __FILE__, __LINE__
+#define LOG_MAP_FL LOG_KIND_MAP, __FILE__, __LINE__
+#define LOG_JVMTI_FL LOG_KIND_JVMTI, __FILE__, __LINE__
+#define LOG_FUNC_FL LOG_KIND_FUNC, __FILE__, __LINE__
+#define LOG_MON_FL LOG_KIND_MON, __FILE__, __LINE__
+#define LOG_UTIL_FL LOG_KIND_UTIL, __FILE__, __LINE__
+#define LOG_PROG_FL LOG_KIND_PROG, __FILE__, __LINE__
+#define LOG_LOG_FL LOG_KIND_LOG, __FILE__, __LINE__
+#define LOG_INFO_FL LOG_KIND_INFO, __FILE__, __LINE__
+#define LOG_ERROR_FL LOG_KIND_ERROR, __FILE__, __LINE__
+#define LOG_SIMPLE_FL LOG_KIND_SIMPLE, __FILE__, __LINE__
+#define LOG_NUM_FL LOG_KIND_NUM, __FILE__, __LINE__
+
 
 #endif // _LOG_H_

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/LogManager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/LogManager.cpp?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/LogManager.cpp (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/LogManager.cpp Thu Jul 16 15:57:37 2009
@@ -15,23 +15,19 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.15 $
- */
-// LogManager.cpp
-
-#include <iostream>
-#include <fstream>
-#include <cstring>
-#include <string>
+#ifndef USING_VMI
+#define USING_VMI
+#endif
 
 #include "LogManager.h"
 #include "AgentMonitor.h"
+#include "AgentBase.h"
+#include "vmi.h"
+#include "hyport.h"
+
+#include <string.h>
 
 using namespace jdwp;
-using namespace std;
 
 static struct {
     const char* disp;
@@ -53,11 +49,11 @@
     { " PROG", "PROG" },
     { "  LOG", "LOG" },
     { " INFO", "INFO" },
-    { "ERROR", "ERROR" }
+    { "ERROR", "ERROR" },
+    { "SIMPLE", "SIMPLE" } 
 };
 
-STDLogManager::STDLogManager() throw() :
-    m_logStream(&clog),
+STDLogManager::STDLogManager() :
     m_fileFilter(0),
     m_monitor(0)
 {
@@ -69,7 +65,6 @@
 }
 
 void STDLogManager::Init(const char* log, const char* kindFilter, const char* srcFilter)
-    throw(AgentException)
 {
     if (srcFilter != 0 && strcmp("all", srcFilter) == 0) {
         srcFilter = 0; // null equvivalent to "all"
@@ -101,29 +96,32 @@
 
     m_logKinds[LOG_KIND_INFO] = TRACE_KIND_ALWAYS;
     m_logKinds[LOG_KIND_ERROR] = TRACE_KIND_ALWAYS;
+    m_logKinds[LOG_KIND_SIMPLE] = TRACE_KIND_ALWAYS;
 
     if (log == 0) {
-        m_logStream = &clog;
+        m_fileHandle = -1;
     } else {
-        m_logStream = new ofstream(log);
-        if (m_logStream == 0) {
-            fprintf(stderr, "Cannot open log file: %s\n", log);
-            m_logStream = &clog;
+        PORT_ACCESS_FROM_JAVAVM(AgentBase::GetJavaVM());
+        hyfile_unlink(log); // We do not care about the result of unlink here, failure may be because the file does not exist
+        m_fileHandle = hyfile_open(log, HyOpenCreate | HyOpenWrite, 0660);
+        if (m_fileHandle == -1) {
+            hytty_printf(privatePortLibrary, "Cannot open log file: %s", log);
         }
     }
 
     m_monitor = new AgentMonitor("_agent_Log");
 }
 
-void STDLogManager::Clean() throw()
+void STDLogManager::Clean()
 {
     if (m_monitor != 0) {
         m_monitor->Enter();
     }
 
-    if (m_logStream != &clog) {
-        delete m_logStream;
-        m_logStream = &clog;
+    if (m_fileHandle != -1) {
+        PORT_ACCESS_FROM_JAVAVM(AgentBase::GetJavaVM());
+        hyfile_close(m_fileHandle);
+        m_fileHandle = -1;
     }
 
     // prevent logging in destruction of log's monitor
@@ -137,7 +135,7 @@
 
 // extract basename from filename
 
-const char* STDLogManager::BaseName(const char* filepath) throw()
+const char* STDLogManager::BaseName(const char* filepath)
 {
     size_t len;
 
@@ -157,64 +155,76 @@
     return filepath;
 }
 
-// STDLogManager intended to use cout, cerr and clog streams.
+void STDLogManager::Tracev(int kind, const char* file, int line, const char* format, va_list args) {
+    // No need to check kind here, as this is a private function and all public functions using it should check kind before calling tracev
+    PORT_ACCESS_FROM_JAVAVM(AgentBase::GetJavaVM());
+    if (m_monitor != 0) {
+        m_monitor->Enter();
+    }
 
-void STDLogManager::Info(const std::string& message,
-        const char *file, int line) throw()
-{
-    Trace(message, file, line, LOG_KIND_INFO);
-}
+    I_64 timeMillis = hytime_current_time_millis();
+    char timestamp[9]; // Buffer for the timestamp
+    hystr_ftime(timestamp, 9, "%H:%M:%S");
+
+    int currentMillis = (int)(timeMillis%1000); // get the 1000ths of a second
+
+    char message[5000]; //Buffer of a large size, big enough to contain formatted message strings
+    hystr_vprintf(message, 5000, format, args);
+
+    file = BaseName(file);
+    if (LOG_KIND_SIMPLE == kind) {
+        hyfile_printf(privatePortLibrary, HYPORT_TTY_OUT, "%s\n", message);
+    } else {
+        hyfile_printf(privatePortLibrary, HYPORT_TTY_ERR, "%s.%03d %s: [%s:%d] %s\n", timestamp, currentMillis, s_logKinds[kind].disp, file, line, message);
+    }
 
-void STDLogManager::Error(const std::string& message,
-        const char *file, int line) throw()
-{
-    Trace(message, file, line, LOG_KIND_ERROR);
-}
+    // duplicate ERROR and INFO message in the log and in the cerr/cout output
+    if (m_fileHandle != -1) {
+        hyfile_printf(privatePortLibrary, m_fileHandle, "%s.%03d %s: [%s:%d] %s\n", timestamp, currentMillis, s_logKinds[kind].disp, file, line, message);
+    }
 
-void STDLogManager::Log(const std::string& message,
-        const char *file, int line) throw()
-{
-    Trace(message, file, line, LOG_KIND_LOG);
+    if (m_monitor != 0) {
+        m_monitor->Exit();
+    }
 }
 
-void STDLogManager::Trace(const string& message,
-        const char *file, int line, int kind) throw()
-{
-    if (TraceEnabled(file, line, kind)){
-        if (m_monitor != 0) {
-            m_monitor->Enter();
-        }
+void STDLogManager::Trace(int kind, const char* file, int line, const char* format, ...) {
+    PORT_ACCESS_FROM_JAVAVM(AgentBase::GetJavaVM());
+    va_list args;
+    va_start(args, format);    
+    Tracev(kind, file, line, format, args);
+    va_end(args);
+}
 
-        file = BaseName(file);
-        std::ostream* logStream = m_logStream;
-        if (LOG_KIND_ERROR == kind) {
-            logStream = &cerr;
-        }
-        else if (LOG_KIND_INFO == kind) {
-            logStream = &cout;
-        }
+void STDLogManager::TraceEnter(int kind, const char* file, int line, const char* format, ...) {
+    PORT_ACCESS_FROM_JAVAVM(AgentBase::GetJavaVM());
+    char *message = (char*)hymem_allocate_memory(strlen(format) + 4);
+    va_list args;
+    va_start(args, format);
+    hystr_printf(privatePortLibrary, message, (U_32)(strlen(format) + 4), ">> %s", format);
+    Tracev(kind, file, line, message, args);
+    va_end(args);
+    hymem_free_memory(message);
+}
 
-        *logStream
-                << s_logKinds[kind].disp << ": "
-                << "[" << file << ":" << line << "] "
-                << message << endl;
-
-        // duplicate ERROR and INFO message in the log and in the cerr/cout output
-        if (logStream != m_logStream && m_logStream != &clog) {
-            *m_logStream
-                << s_logKinds[kind].disp << ": "
-                << "[" << file << ":" << line << "] "
-                << message << endl;
-        }
+void STDLogManager::TraceExit(int kind, const char* file, int line, const char* format) {
+    PORT_ACCESS_FROM_JAVAVM(AgentBase::GetJavaVM());
+    const char *openBracket = strchr(format, '(');
+    char *message = (char*)hymem_allocate_memory(openBracket - format + 3);
+    hystr_printf(privatePortLibrary, message, (U_32)(openBracket - format + 2), format);
+    Trace(kind, file, line, "<< %s)", message);
+    hymem_free_memory(message);
+}
 
-        if (m_monitor != 0) {
-            m_monitor->Exit();
-        }
-    }
+void STDLogManager::TraceEnterv(int kind, const char* file, int line, const char* format, va_list args) {
+    PORT_ACCESS_FROM_JAVAVM(AgentBase::GetJavaVM());
+    char *message = (char*)hymem_allocate_memory(strlen(format) + 5);
+    hystr_printf(privatePortLibrary, message, (U_32)(strlen(format) + 4), ">> %s", format);
+    Tracev(kind, file, line, message, args);
+    hymem_free_memory(message);
 }
 
-bool STDLogManager::TraceEnabled(const char *file, int line, int kind) throw()
-{
+bool STDLogManager::TraceEnabled(int kind, const char* file, int line, const char* format, ...) {
     if (TRACE_KIND_FILTER_FILE == m_logKinds[kind]) {
         return strstr(m_fileFilter, BaseName(file)) != 0;
     }
@@ -222,3 +232,4 @@
         return TRACE_KIND_ALWAYS == m_logKinds[kind];
     }
 }
+

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/LogManager.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/LogManager.h?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/LogManager.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/LogManager.h Thu Jul 16 15:57:37 2009
@@ -15,12 +15,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.12.2.1 $
- */
-
 /**
  * @file
  * LogManager.h
@@ -30,10 +24,10 @@
 #ifndef _LOG_MANAGER_H_
 #define _LOG_MANAGER_H_
 
-#include <iostream>
-#include <string>
-
-#include "AgentException.h"
+#include <stdarg.h>
+#include <stdlib.h>
+#include "vmi.h"
+#include "hyport.h"
 
 namespace jdwp {
 
@@ -57,7 +51,7 @@
         LOG_KIND_LOG,
         LOG_KIND_INFO,
         LOG_KIND_ERROR,
-
+        LOG_KIND_SIMPLE,
         LOG_KIND_NUM
     };
 
@@ -82,54 +76,21 @@
         /**
          * Initializes the log manager.
          */
-        virtual void Init(const char* log, const char* kindFilter, const char* srcFilter)
-            throw(AgentException) = 0;
+        virtual void Init(const char* log, const char* kindFilter, const char* srcFilter) {};
 
         /**
          * Cleanups the log manager.
          */
-        virtual void Clean() throw() = 0;
+        virtual void Clean() {};
 
-        /**
-         * Prints the given message of the Info type.
-         *
-         * @param message - the log message
-         * @param file    - the name of the source file (__FILE__ macro)
-         * @param line    - the number of the code line (__LINE__ macro)
-         */
-        virtual void Info(const std::string& message,
-            const char *file, int line) throw() = 0;
+        /* Trace methods */
+        virtual void Trace(int kind, const char* file, int line, const char* format, ...) {};
 
-        /**
-         * Prints the given message of the Error type.
-         *
-         * @param message - the log message
-         * @param file    - the name of the source file (__FILE__ macro)
-         * @param line    - the number of the code line (__LINE__ macro)
-         */
-        virtual void Error(const std::string& message,
-            const char *file, int line) throw() = 0;
+        virtual void TraceEnter(int kind, const char* file, int line, const char* format, ...) {};
+        virtual void TraceEnterv(int kind, const char* file, int line, const char* format, va_list args) {};
+        virtual void TraceExit(int kind, const char* file, int line, const char* format) {};        
 
-        /**
-         * Prints the given message of the Log type.
-         *
-         * @param message - the log message
-         * @param file    - the name of the source file (__FILE__ macro)
-         * @param line    - the number of the code line (__LINE__ macro)
-         */
-        virtual void Log(const std::string& message,
-            const char *file, int line) throw() = 0;
-
-        /**
-         * Prints the given message of the Trace type.
-         *
-         * @param message - the log message
-         * @param file    - the name of the source file (__FILE__ macro)
-         * @param line    - the number of the code line (__LINE__ macro)
-         * @param kind    - the log kind
-         */
-        virtual void Trace(const std::string& message,
-            const char *file, int line, int kind) throw() = 0;
+        static inline void EmptyFunction(int kind, const char* file, int line, const char* format, ...) {};
 
         /**
          * Checks whether the print to log is enabled for the Trace log type.
@@ -140,7 +101,18 @@
          *
          * @return Boolean.
          */
-        virtual bool TraceEnabled(const char *file, int line, int kind) throw() = 0;
+        virtual bool TraceEnabled(int kind, const char* file, int line, const char* format, ...) {return false;};
+
+        inline void* operator new(size_t size) {
+            return malloc(size);
+        }
+
+        inline void operator delete(void* ptr) {
+            free(ptr);
+        }
+
+    private:
+        virtual void Tracev(int kind, const char* file, int line, const char* format, va_list args) {};
     };
 
     /**
@@ -153,59 +125,25 @@
         /**
          * A constructor.
          */
-        STDLogManager() throw();
+        STDLogManager();
 
         /**
          * Initializes the log manager.
          */
-        void Init(const char* log, const char* kindFilter, const char* srcFilter)
-            throw(AgentException);
+        void Init(const char* log, const char* kindFilter, const char* srcFilter);
 
         /**
          * Cleanups the log manager.
          */
-        void Clean() throw();
+        void Clean();
 
-        /**
-         * Prints the given message of the Info type.
-         *
-         * @param message - the log message
-         * @param file    - the name of the source file (__FILE__ macro)
-         * @param line    - the number of the code line (__LINE__ macro)
-         */
-        void Info(const std::string& message,
-            const char *file, int line) throw();
-
-        /**
-         * Prints the given message of the Error type.
-         *
-         * @param message - the log message
-         * @param file    - the name of the source file (__FILE__ macro)
-         * @param line    - the number of the code line (__LINE__ macro)
-         */
-        void Error(const std::string& message,
-            const char *file, int line) throw();
+        /* Trace methods */
+        void Trace(int kind, const char* file, int line, const char* format, ...);
 
-        /**
-         * Prints the given message of the Log type.
-         *
-         * @param message - the log message
-         * @param file    - the name of the source file (__FILE__ macro)
-         * @param line    - the number of the code line (__LINE__ macro)
-         */
-        void Log(const std::string& message,
-            const char *file, int line) throw();
+        void TraceEnter(int kind, const char* file, int line, const char* format, ...);
+        void TraceEnterv(int kind, const char* file, int line, const char* format, va_list args);
+        void TraceExit(int kind, const char* file, int line, const char* format);
 
-        /**
-         * Prints the given message of the Trace type.
-         *
-         * @param message - the log message
-         * @param file    - the name of the source file (__FILE__ macro)
-         * @param line    - the number of the code line (__LINE__ macro)
-         * @param kind    - the log kind
-         */
-        void Trace(const std::string& message,
-            const char *file, int line, int kind) throw();
 
         /**
          * Checks whether the print to log is enabled for the Trace log type.
@@ -216,7 +154,7 @@
          *
          * @return Boolean.
          */
-        bool TraceEnabled(const char *file, int line, int kind) throw();
+        bool TraceEnabled(int kind, const char* file, int line, const char* format, ...);
 
         /**
          * Gets a short file name from the full path.
@@ -225,14 +163,17 @@
          *
          * @return Zero terminated string.
          */
-        static const char* BaseName(const char* filepath) throw();
+        static const char* BaseName(const char* filepath);
 
     private:
+        void Tracev(int kind, const char* file, int line, const char* format, va_list args);
+
         const char*     m_fileFilter;
-        std::ostream*   m_logStream;
+        IDATA           m_fileHandle;
         AgentMonitor*   m_monitor;
         int             m_logKinds[LOG_KIND_NUM];
     };
+
 }
 
 #endif // _LOG_MANAGER_H_

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/MemoryManager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/MemoryManager.cpp?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/MemoryManager.cpp (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/MemoryManager.cpp Thu Jul 16 15:57:37 2009
@@ -16,97 +16,107 @@
  *  limitations under the License.
  */
 
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.5 $
- */
-// MemoryManager.cpp
-
-#include <cstdlib>
-#include <cstring>
-
-#include "AgentException.h"
 #include "MemoryManager.h"
+#include "ExceptionManager.h"
 #include "AgentBase.h"
-//#include "Log.h"
+#include "Log.h"
 //#include "jvmti.h"
 
+#include <string.h>
+#include <stdlib.h> 
+
 using namespace jdwp;
 
-// STDMemoryManager intended to use std::malloc(), std::free() etc.
+// should never be invoked
+void *operator new(size_t size)
+{
+    void* p = malloc(size);
+    JDWP_TRACE(LOG_RELEASE, (LOG_KIND_MEMORY, __FILE__, __LINE__, "VM malloc: %lld, %p", static_cast<long long>(size), p));
+    return p;
+}
+
+// should never be invoked
+void operator delete(void *p)
+{
+    JDWP_TRACE(LOG_RELEASE, (LOG_KIND_MEMORY, __FILE__, __LINE__, "VM free: %p", p));
+    free(p);
+}
 
-void* STDMemoryManager::AllocateNoThrow(size_t size JDWP_FILE_LINE_PAR) throw() {
-    void *p = std::malloc(size);
-    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "STD malloc: " << static_cast<long long>(size) << " " << p);
+// STDMemoryManager intended to use malloc(), free() etc.
+
+void* STDMemoryManager::AllocateNoThrow(size_t size JDWP_FILE_LINE_PAR) {
+    void *p = malloc(size);
+    JDWP_TRACE(LOG_RELEASE, (LOG_KIND_MEMORY, file, line, "STD malloc: %lld %p", static_cast<long long>(size), p));
     return p;
 }
 
-void* STDMemoryManager::Allocate(size_t size JDWP_FILE_LINE_PAR) throw(AgentException) {
-    void *p = std::malloc(size);
-    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "STD malloc: " << static_cast<long long>(size) << " " << p);
+void* STDMemoryManager::Allocate(size_t size JDWP_FILE_LINE_PAR) {
+    void *p = malloc(size);
+    JDWP_TRACE(LOG_RELEASE, (LOG_KIND_MEMORY, file, line, "STD malloc: %lld %p", static_cast<long long>(size), p));
     if (p == 0) {
-        throw OutOfMemoryException();
+        JDWP_TRACE(LOG_RELEASE, (LOG_KIND_ERROR, file, line, "STD malloc failed: %lld %p", static_cast<long long>(size), p));
     }
     return p;
 }
 
 void* STDMemoryManager::Reallocate(void* ptr, size_t oldSize, size_t newSize JDWP_FILE_LINE_PAR)
-        throw(AgentException) {
-    void *p = std::realloc(ptr, newSize);
-    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "STD realloc: " << ptr << " " << static_cast<long long>(oldSize)
-        << "/" << static_cast<long long>(newSize) << " " << p);
+        {
+    void *p = realloc(ptr, newSize);
+    JDWP_TRACE(LOG_RELEASE, (LOG_KIND_MEMORY, file, line, "STD realloc: %p %lld/%lld %p", ptr, static_cast<long long>(oldSize),
+        static_cast<long long>(newSize), p));
     if (p == 0) {
-        throw OutOfMemoryException();
-    }
+        JDWP_TRACE(LOG_RELEASE, (LOG_KIND_ERROR, file, line, "STD realloc failed: %p %lld/%lld %p", ptr, static_cast<long long>(oldSize),
+                                 static_cast<long long>(newSize), p));
+    }    
     return p;
 }
 
-void STDMemoryManager::Free(void* ptr JDWP_FILE_LINE_PAR) throw() {
-    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "STD free: " << ptr);
-    std::free(ptr);
+void STDMemoryManager::Free(void* ptr JDWP_FILE_LINE_PAR) {
+    JDWP_TRACE(LOG_RELEASE, (LOG_KIND_MEMORY, file, line, "STD free: %p", ptr));
+    free(ptr);
 }
 
 
 // VMMemoryManager intended to use JVMTI's Allocate() and Deallocate()
 
-void* VMMemoryManager::AllocateNoThrow(size_t size JDWP_FILE_LINE_PAR) throw() {
+void* VMMemoryManager::AllocateNoThrow(size_t size JDWP_FILE_LINE_PAR) {
     void *p;
 
     jvmtiError err;
-    JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->Allocate(size,
+    JVMTI_TRACE(LOG_DEBUG, err, AgentBase::GetJvmtiEnv()->Allocate(size,
         reinterpret_cast<unsigned char**>(&p)));
-    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "VM malloc: " << static_cast<long long>(size) << ", " << p);
+    JDWP_TRACE(LOG_RELEASE, (LOG_KIND_MEMORY, file, line, "VM malloc: %lld, %p", static_cast<long long>(size), p));
     return ((err == JVMTI_ERROR_NONE) ? p : 0);
 }
 
-void* VMMemoryManager::Allocate(size_t size JDWP_FILE_LINE_PAR) throw(AgentException) {
+void* VMMemoryManager::Allocate(size_t size JDWP_FILE_LINE_PAR) {
     void *p;
 
     jvmtiError err;
-    JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->Allocate(size,
+    JVMTI_TRACE(LOG_DEBUG, err, AgentBase::GetJvmtiEnv()->Allocate(size,
         reinterpret_cast<unsigned char**>(&p)));
-    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "VM malloc: " << static_cast<long long>(size) << ", " << p);
+    JDWP_TRACE(LOG_RELEASE, (LOG_KIND_MEMORY, file, line, "VM malloc: %lld, %p", static_cast<long long>(size), p));
     if (err != JVMTI_ERROR_NONE) {
-        throw AgentException(err);
+        JDWP_TRACE(LOG_RELEASE, (LOG_KIND_ERROR, file, line, "VM malloc failed: %lld, %p", static_cast<long long>(size), p));
     }
-
     return p;
 }
 
 void* VMMemoryManager::Reallocate(void* ptr, size_t oldSize, size_t newSize JDWP_FILE_LINE_PAR)
-        throw(AgentException) {
+        {
     void *p;
 
     jvmtiError err;
-    JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->Allocate(newSize,
+    JVMTI_TRACE(LOG_DEBUG, err, AgentBase::GetJvmtiEnv()->Allocate(newSize,
         reinterpret_cast<unsigned char**>(&p)));
-    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "VM realloc: " << ptr << " " << static_cast<long long>(oldSize)
-        << "/" << static_cast<long long>(newSize) << " " << p);
+    JDWP_TRACE(LOG_RELEASE, (LOG_KIND_MEMORY, file, line, "VM realloc: %p %lld/%lld %p", ptr, static_cast<long long>(oldSize),
+        static_cast<long long>(newSize), p));
     if (err != JVMTI_ERROR_NONE) {
-        throw AgentException(err);
+        JDWP_TRACE(LOG_RELEASE, (LOG_KIND_ERROR, file, line, "VM realloc failed: %p %lld/%lld %p", ptr, static_cast<long long>(oldSize),
+                                 static_cast<long long>(newSize), p));
     } else {
-        std::memcpy(p, ptr, (newSize < oldSize) ? newSize : oldSize);
-        JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->Deallocate(
+        memcpy(p, ptr, (newSize < oldSize) ? newSize : oldSize);
+        JVMTI_TRACE(LOG_DEBUG, err, AgentBase::GetJvmtiEnv()->Deallocate(
             reinterpret_cast<unsigned char*>(ptr)));
         JDWP_ASSERT(err==JVMTI_ERROR_NONE);
     }
@@ -114,10 +124,10 @@
     return p;
 }
 
-void VMMemoryManager::Free(void* ptr JDWP_FILE_LINE_PAR) throw() {
-    JDWP_TRACE_EX(LOG_KIND_MEMORY, file, line, "VM free: " << ptr);
+void VMMemoryManager::Free(void* ptr JDWP_FILE_LINE_PAR) {
+    JDWP_TRACE(LOG_RELEASE, (LOG_KIND_MEMORY, file, line, "VM free: %p", ptr));
     jvmtiError err;
-    JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->Deallocate(
+    JVMTI_TRACE(LOG_DEBUG, err, AgentBase::GetJvmtiEnv()->Deallocate(
         reinterpret_cast<unsigned char*>(ptr)));
     JDWP_ASSERT(err==JVMTI_ERROR_NONE);
 }

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/MemoryManager.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/MemoryManager.h?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/MemoryManager.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/MemoryManager.h Thu Jul 16 15:57:37 2009
@@ -15,12 +15,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.6.2.1 $
- */
-
 /**
  * @file
  * MemoryManager.h
@@ -30,11 +24,15 @@
 #ifndef _MEMORY_MANAGER_H_
 #define _MEMORY_MANAGER_H_
 
-#include "AgentException.h"
 #include "Log.h"
 
+void *operator new(size_t size);
+
+void operator delete(void *p);
+
 namespace jdwp {
 
+
     /**
      * Agent memory manager interface.
      */
@@ -51,7 +49,7 @@
          * @return Pointer to the allocated memory block.
          */
         virtual void* AllocateNoThrow(size_t size
-            JDWP_FILE_LINE_PAR) throw() = 0;
+				      JDWP_FILE_LINE_PAR) {return 0;};
 
         /**
          * Allocates the memory block with the given size.
@@ -64,7 +62,7 @@
          *            <code>OutOfMemoryException</code> is thrown.
          */
         virtual void* Allocate(size_t size
-            JDWP_FILE_LINE_PAR) throw(AgentException) = 0;
+			       JDWP_FILE_LINE_PAR) {return 0;};
 
         /**
          * Reallocates the memory block with the given size over the previously
@@ -78,7 +76,7 @@
          *            <code>OutOfMemoryException</code> is thrown.
          */
         virtual void* Reallocate(void* ptr, size_t oldSize, size_t newSize
-            JDWP_FILE_LINE_PAR) throw(AgentException) = 0;
+				 JDWP_FILE_LINE_PAR) {return 0;};
 
         /**
          * Frees the memory block with the given size.
@@ -86,7 +84,15 @@
          * @param ptr - the pointer to the allocated memory block
          */
         virtual void Free(void* ptr
-            JDWP_FILE_LINE_PAR) throw() = 0;
+            JDWP_FILE_LINE_PAR) {};
+
+	inline void* operator new(size_t size) {
+	    return malloc(size);
+	}
+
+	inline void operator delete(void* ptr) {
+	    free(ptr);
+	}
     };
 
     /**
@@ -106,7 +112,7 @@
          * @return Pointer to the allocated memory block.
          */
         void* AllocateNoThrow(size_t size
-            JDWP_FILE_LINE_PAR) throw();
+            JDWP_FILE_LINE_PAR);
 
         /**
          * Allocates the memory block with the given size.
@@ -119,7 +125,7 @@
          *            <code>OutOfMemoryException</code> is thrown.
          */
         void* Allocate(size_t size
-            JDWP_FILE_LINE_PAR) throw(AgentException);
+            JDWP_FILE_LINE_PAR) ;
 
         /**
          * Reallocates the memory block with the given size over the previously
@@ -133,7 +139,7 @@
          *            <code>OutOfMemoryException</code> is thrown.
          */
         void* Reallocate(void* ptr, size_t oldSize, size_t newSize
-            JDWP_FILE_LINE_PAR) throw(AgentException);
+            JDWP_FILE_LINE_PAR);
 
         /**
          * Frees the memory block with the given size.
@@ -141,7 +147,7 @@
          * @param ptr - the pointer to the allocated memory block
          */
         void Free(void* ptr
-            JDWP_FILE_LINE_PAR) throw();
+            JDWP_FILE_LINE_PAR);
     };
 
 
@@ -162,7 +168,7 @@
          * @return Pointer to the allocated memory block.
          */
         void* AllocateNoThrow(size_t size
-            JDWP_FILE_LINE_PAR) throw();
+            JDWP_FILE_LINE_PAR);
 
         /**
          * Allocates the memory block with the given size.
@@ -175,7 +181,7 @@
          *            <code>OutOfMemoryException</code> is thrown.
          */
         void* Allocate(size_t size
-            JDWP_FILE_LINE_PAR) throw(AgentException);
+            JDWP_FILE_LINE_PAR);
 
         /**
          * Reallocates the memory block with the given size over the previously
@@ -189,7 +195,7 @@
          *            <code>OutOfMemoryException</code> is thrown.
          */
         void* Reallocate(void* ptr, size_t oldSize, size_t newSize
-            JDWP_FILE_LINE_PAR) throw(AgentException);
+            JDWP_FILE_LINE_PAR);
 
         /**
          * Frees the memory block with the given size.
@@ -197,7 +203,7 @@
          * @param ptr - the pointer to the allocated memory block
          */
         void Free(void* ptr
-            JDWP_FILE_LINE_PAR) throw();
+            JDWP_FILE_LINE_PAR);
     };
 }
 



Mime
View raw message