Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 98150 invoked from network); 7 May 2008 11:41:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 May 2008 11:41:54 -0000 Received: (qmail 99740 invoked by uid 500); 7 May 2008 11:41:56 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 99637 invoked by uid 500); 7 May 2008 11:41:56 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 99626 invoked by uid 99); 7 May 2008 11:41:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 May 2008 04:41:56 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 May 2008 11:41:16 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 548B92388A09; Wed, 7 May 2008 04:41:31 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r654075 - in /harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp: common/agent/commands/ common/agent/core/ common/generic/ common/transport/common/ common/transport/dt_socket/ unix/agent/ unix/agent/core/ unix/trans... Date: Wed, 07 May 2008 11:41:28 -0000 To: commits@harmony.apache.org From: lvjing@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080507114131.548B92388A09@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: lvjing Date: Wed May 7 04:41:26 2008 New Revision: 654075 URL: http://svn.apache.org/viewvc?rev=654075&view=rev Log: modify according to new j9 portlib update. Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/core/TransportManager_pd.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/makefile harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/dt_socket/SocketTransport_pd.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/makefile harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/core/TransportManager_pd.cpp harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/makefile harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/dt_socket/SocketTransport_pd.h harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/makefile Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp Wed May 7 04:41:26 2008 @@ -82,8 +82,8 @@ // Can be: JVMTI_ERROR_INVALID_CLASS, JVMTI_ERROR_NULL_POINTER throw AgentException(err); } - jint const JVMTI_CLASS_STATUS_PREPARED = 0x2; - if ( (status & JVMTI_CLASS_STATUS_PREPARED) == 0 ) { + // jint const JVMTI_CLASS_STATUS_PREPARED = 0x2 ; + if ( (status & 0x2) == 0 ) { throw AgentException(JDWP_ERROR_CLASS_NOT_PREPARED); } Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.cpp?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.cpp Wed May 7 04:41:26 2008 @@ -249,7 +249,7 @@ JDWP_TRACE_MAP("## DisableCollection: NewGlobalRef returned NULL"); throw OutOfMemoryException(); } - JNIEnvPtr->DeleteWeakGlobalRef(jvmObject); + JNIEnvPtr->DeleteWeakGlobalRef((jweak)jvmObject); objectIDItem->mapObjectIDItem.globalRefKind = NORMAL_GLOBAL_REF; objectIDItem->mapObjectIDItem.jvmObject = newGlobRef; } // synchronized block: objectIDTableLock @@ -431,7 +431,7 @@ if (objectIDItem->mapObjectIDItem.globalRefKind == NORMAL_GLOBAL_REF) { JNIEnvPtr->DeleteGlobalRef(jvmObject); } else { - JNIEnvPtr->DeleteWeakGlobalRef(jvmObject); + JNIEnvPtr->DeleteWeakGlobalRef((jweak)jvmObject); } objectIDItem->objectID = FREE_OBJECTID_SIGN; objectIDItem->nextFreeObjectIDItem = m_freeObjectIDItems[idx]; @@ -503,7 +503,7 @@ if (objectIDItem->mapObjectIDItem.globalRefKind == NORMAL_GLOBAL_REF) { JNIEnvPtr->DeleteGlobalRef(objectIDItem->mapObjectIDItem.jvmObject); } else { - JNIEnvPtr->DeleteWeakGlobalRef(objectIDItem->mapObjectIDItem.jvmObject); + JNIEnvPtr->DeleteWeakGlobalRef((jweak)objectIDItem->mapObjectIDItem.jvmObject); } } objectIDItem++; @@ -643,7 +643,7 @@ for (size_t idx = 0; idx < HASH_TABLE_SIZE; idx++) { if (m_refTypeIDTable[idx]) { for (size_t item = 0; item < m_refTypeIDTableUsed[idx]; item++) - JNIEnvPtr->DeleteWeakGlobalRef(m_refTypeIDTable[idx][item]); + JNIEnvPtr->DeleteWeakGlobalRef((jweak)m_refTypeIDTable[idx][item]); GetMemoryManager().Free(m_refTypeIDTable[idx] JDWP_FILE_LINE); m_refTypeIDTable[idx] = NULL; m_refTypeIDTableUsed[idx] = m_refTypeIDTableSize[idx] = 0; @@ -925,7 +925,7 @@ threadFramesItem++; continue; } - JNIEnvPtr->DeleteWeakGlobalRef(threadFramesItem->jvmThread); + JNIEnvPtr->DeleteWeakGlobalRef((jweak)threadFramesItem->jvmThread); threadFramesItem++; } AgentBase::GetMemoryManager().Free(m_frameIDTable JDWP_FILE_LINE); Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.h?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ObjectManager.h Wed May 7 04:41:26 2008 @@ -38,6 +38,10 @@ #include "jdwpTypes.h" #include "AgentMonitor.h" +#if defined(ZOS) +#include +#endif + namespace jdwp { // hash table parameters Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.cpp Wed May 7 04:41:26 2008 @@ -23,8 +23,11 @@ // TransportManager.cpp // +#ifndef USING_VMI +#define USING_VMI #include "TransportManager.h" + using namespace jdwp; static void* @@ -63,12 +66,13 @@ GetMemoryManager().Free(m_address JDWP_FILE_LINE); } if (m_loadedLib != 0) { - jdwpTransport_UnLoad_Type UnloadFunc = reinterpret_cast - (GetProcAddress(m_loadedLib, unLoadDecFuncName)); - if ((UnloadFunc != 0) && (m_env != 0)) { - (UnloadFunc) (&m_env); - } - FreeLibrary(m_loadedLib); + PORT_ACCESS_FROM_JAVAVM(GetJavaVM()); + //jdwpTransport_UnLoad_Type UnloadFunc = reinterpret_cast + // (GetProcAddress(m_loadedLib, unLoadDecFuncName)); + j9sl_close_shared_library ((UDATA)m_loadedLib); + //if ((UnloadFunc != 0) && (m_env != 0)) { + // (UnloadFunc) (&m_env); + //} } } //TransportManager::~TransportManager() @@ -120,8 +124,10 @@ throw TransportException(JDWP_ERROR_TRANSPORT_LOAD, JDWPTRANSPORT_ERROR_NONE, m_lastErrorMessage); } - jdwpTransport_OnLoad_t transportOnLoad = reinterpret_cast - (GetProcAddress(m_loadedLib, onLoadDecFuncName)); + PORT_ACCESS_FROM_JAVAVM(GetJavaVM()); + + jdwpTransport_OnLoad_t transportOnLoad; + UDATA ret = j9sl_lookup_name((UDATA)m_loadedLib, (char*) onLoadDecFuncName, (UDATA*) &transportOnLoad, "ILLIL"); if (transportOnLoad == 0) { if (m_lastErrorMessage != 0) { GetMemoryManager().Free(m_lastErrorMessage JDWP_FILE_LINE); @@ -133,7 +139,8 @@ JDWP_ERROR(onLoadDecFuncName << " function not found in " << transportName); throw TransportException(JDWP_ERROR_TRANSPORT_INIT, JDWPTRANSPORT_ERROR_NONE, m_lastErrorMessage); } - jint res = (*transportOnLoad)(GetJavaVM(), &callback, JDWPTRANSPORT_VERSION_1_0, &m_env); + + jint res = (*transportOnLoad)(GetJavaVM(), &callback, JDWPTRANSPORT_VERSION_1_0, &m_env); if (res == JNI_ENOMEM) { if (m_lastErrorMessage != 0) { GetMemoryManager().Free(m_lastErrorMessage JDWP_FILE_LINE); @@ -351,3 +358,47 @@ << " cmd=" << (int)(packet->type.cmd.cmd)); } } // TransportManager::TracePacket() + +LoadedLibraryHandler TransportManager::LoadTransport(const char* dirName, const char* transportName) +{ +// JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(GetJavaVM()); + + JDWP_TRACE_ENTRY("LoadTransport(" << JDWP_CHECK_NULL(dirName) << ',' << JDWP_CHECK_NULL(transportName) << ')'); + + JDWP_ASSERT(transportName != 0); + char* transportFullName = 0; +#ifdef WIN32 + if (dirName == 0) { + size_t length = strlen(transportName) + 5; + transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); + sprintf(transportFullName, "%s.dll", transportName); + } else { + size_t length = strlen(dirName) + strlen(transportName) + 6; + transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); + sprintf(transportFullName, "%s\\%s.dll", dirName, transportName); + } +#else + if (dirName == 0) { + size_t length = strlen(transportName) + 7; + transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); + sprintf(transportFullName, "lib%s.so", transportName); + } else { + size_t length = strlen(dirName) + strlen(transportName) + 8; + transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); + sprintf(transportFullName, "%s/lib%s.so", dirName, transportName); + } +#endif +// AgentAutoFree afv(transportFullName JDWP_FILE_LINE); + UDATA res; + UDATA ret = j9sl_open_shared_library(transportFullName,(UDATA *)&res, FALSE); + if (ret != 0) { + JDWP_TRACE_PROG("LoadTransport: loading library " << transportFullName << " failed (error code: " << j9error_last_error_message() << ")"); + //JDWP_TRACE_PROG("LoadTransport: loading library " << transportFullName << " failed (error code: " << GetLastTransportError() << ")"); + } else { + JDWP_TRACE_PROG("LoadTransport: transport library " << transportFullName << " loaded"); + } + return (LoadedLibraryHandler)res; +} + +#endif Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.h?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/TransportManager.h Wed May 7 04:41:26 2008 @@ -30,11 +30,14 @@ #ifndef _TRANSPORT_MANAGER_H_ #define _TRANSPORT_MANAGER_H_ +#include "TransportManager_pd.h" #include "jdwpTransport.h" #include "AgentBase.h" #include "AgentException.h" #include "Log.h" -#include "TransportManager_pd.h" +#include "vmi.h" +#include "j9thread.h" +#include "j9port.h" namespace jdwp { Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/generic/jdwp.h Wed May 7 04:41:26 2008 @@ -83,8 +83,6 @@ JDWP_COMMAND_VM_REDEFINE_CLASSES = 18, JDWP_COMMAND_VM_SET_DEFAULT_STRATUM = 19, JDWP_COMMAND_VM_ALL_CLASSES_WITH_GENERIC= 20, - //New commands for Java 6 - JDWP_COMMAND_VM_INSTANCE_COUNTS = 21, /* Commands ReferenceType */ JDWP_COMMAND_RT_SIGNATURE = 1, @@ -102,10 +100,6 @@ JDWP_COMMAND_RT_SIGNATURE_WITH_GENERIC = 13, JDWP_COMMAND_RT_FIELDS_WITH_GENERIC = 14, JDWP_COMMAND_RT_METHODS_WITH_GENERIC = 15, - //New commands for Java 6 - JDWP_COMMAND_RT_INSTANCES = 16, - JDWP_COMMAND_RT_CLASS_FILE_VERSION = 17, - JDWP_COMMAND_RT_CONSTANT_POOL = 18, /* Commands ClassType */ JDWP_COMMAND_CT_SUPERCLASS = 1, @@ -132,8 +126,6 @@ JDWP_COMMAND_OR_DISABLE_COLLECTION = 7, JDWP_COMMAND_OR_ENABLE_COLLECTION = 8, JDWP_COMMAND_OR_IS_COLLECTED = 9, - // New commands for Java 6 - JDWP_COMMAND_OR_REFERRING_OBJECTS = 10, /* Commands StringReference */ JDWP_COMMAND_SR_VALUE = 1, @@ -151,9 +143,6 @@ JDWP_COMMAND_TR_STOP = 10, JDWP_COMMAND_TR_INTERRUPT = 11, JDWP_COMMAND_TR_SUSPEND_COUNT = 12, - // New command for Java 6 - JDWP_COMMAND_TR_OWNED_MONITORS_STACK_DEPTH = 13, - JDWP_COMMAND_TR_FORCE_EARLY_RETURN = 14, /* Commands ThreadGroupReference */ JDWP_COMMAND_TGR_NAME = 1, @@ -270,13 +259,7 @@ JDWP_EVENT_VM_INIT = 90, JDWP_EVENT_VM_START = JDWP_EVENT_VM_INIT, JDWP_EVENT_VM_DEATH = 99, - JDWP_EVENT_VM_DISCONNECTED = 100, - // New EventKind constants for Java 6 - JDWP_EVENT_METHOD_EXIT_WITH_RETURN_VALUE = 42, - JDWP_EVENT_MONITOR_CONTENDED_ENTER = 43, - JDWP_EVENT_MONITOR_CONTENDED_ENTERED = 44, - JDWP_EVENT_MONITOR_WAIT = 45, - JDWP_EVENT_MONITOR_WAITED = 46 + JDWP_EVENT_VM_DISCONNECTED = 100 } jdwpEventKind; /* EventRequest/ModifierKind Constants */ @@ -292,9 +275,7 @@ JDWP_MODIFIER_EXCEPTION_ONLY = 8, JDWP_MODIFIER_FIELD_ONLY = 9, JDWP_MODIFIER_STEP = 10, - JDWP_MODIFIER_INSTANCE_ONLY = 11, - // New ModifierKind constants for Java 6 - JDWP_MODIFIER_SOURCE_NAME_MATCH = 12 + JDWP_MODIFIER_INSTANCE_ONLY = 11 } jdwpRequestModifier; /* ThreadStatus Constants */ Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.cpp?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.cpp Wed May 7 04:41:26 2008 @@ -20,14 +20,35 @@ * @author Viacheslav G. Rybalov * @version $Revision: 1.6 $ */ +#include "SocketTransport.h" #include "SocketTransport_pd.h" - +#include "j9thread.h" +#define THREAD_ACCESS_FROM_ENV(jniEnv)\ + VMInterface *threadPrivateVMI = VMI_GetVMIFromJNIEnv(jniEnv);\ + J9PortLibrary *privatePortLibForThread = (*threadPrivateVMI)->GetPortLibrary(threadPrivateVMI);\ + J9ThreadLibrary *privateThreadLibrary = privatePortLibForThread->port_get_thread_library(privatePortLibForThread) void (*LastTransportError::m_free)(void *buffer) = 0; -LastTransportError::LastTransportError(const char* messagePtr, int errorStatus, +static inline ThreadId_t +_GetCurrentThreadId(JNIEnv* jni) +{ + // THREAD_ACCESS_FROM_ENV(jni); + ThreadId_t tid ; + j9thread_attach(&tid); + return tid; +} // GetCurrentThreadId() + + +static inline bool ThreadId_equal(ThreadId_t treadId1, ThreadId_t treadId2) +{ + return (treadId1 == treadId2); +} // ThreadId_equal() + +LastTransportError::LastTransportError(JNIEnv *jni, const char* messagePtr, int errorStatus, void* (*alloc)(jint numBytes), void (*free)(void *buffer)) { - m_treadId = GetCurrentThreadId(); + m_jni = jni; + m_treadId = _GetCurrentThreadId(m_jni); m_lastErrorMessage = messagePtr; m_lastErrorMessagePrefix = ""; m_lastErrorStatus = errorStatus; @@ -65,14 +86,15 @@ jdwpTransportError LastTransportError::insertError(const char* messagePtr, int errorStatus) { - if (ThreadId_equal(m_treadId, GetCurrentThreadId())) { + + if (ThreadId_equal(m_treadId, _GetCurrentThreadId(m_jni))) { m_lastErrorMessage = messagePtr; m_lastErrorStatus = errorStatus; m_lastErrorMessagePrefix = ""; } else if (m_next != 0) { return m_next->insertError(messagePtr, errorStatus); } else { - m_next = new(m_alloc, m_free) LastTransportError(messagePtr, errorStatus, m_alloc, m_free); + m_next = new(m_alloc, m_free) LastTransportError(m_jni, messagePtr, errorStatus, m_alloc, m_free); if (m_next == 0) { return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY; } @@ -83,7 +105,7 @@ jdwpTransportError LastTransportError::addErrorMessagePrefix(const char* prefixPtr) { - if (ThreadId_equal(m_treadId, GetCurrentThreadId())) { + if (ThreadId_equal(m_treadId, _GetCurrentThreadId(m_jni))) { m_lastErrorMessagePrefix = (prefixPtr == 0 ? "" : prefixPtr); } else if (m_next != 0) { return m_next->addErrorMessagePrefix(prefixPtr); @@ -94,7 +116,7 @@ int LastTransportError::GetLastErrorStatus() { - if (ThreadId_equal(m_treadId, GetCurrentThreadId())) { + if (ThreadId_equal(m_treadId, _GetCurrentThreadId(m_jni))) { return m_lastErrorStatus; } else if (m_next != 0) { return m_next->GetLastErrorStatus(); @@ -105,7 +127,7 @@ char* LastTransportError::GetLastErrorMessage() { - if (ThreadId_equal(m_treadId, GetCurrentThreadId())) { + if (ThreadId_equal(m_treadId, _GetCurrentThreadId(m_jni))) { char buf[32]; sprintf(buf, "%d", m_lastErrorStatus); Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.h?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/common/LastTransportError.h Wed May 7 04:41:26 2008 @@ -31,6 +31,11 @@ #define _LASTTRANSPORTERROR_H #include "SocketTransport_pd.h" +#include "jni.h" +#include "jvmti.h" +#include "j9thread.h" +#include "jdwpTransport.h" +typedef j9thread_t ThreadId_t; /** * The given class is a container for message and status code of the last @@ -50,7 +55,7 @@ * @param free - the pointer to the function deallocating the memory * area */ - LastTransportError(const char* messagePtr, int errorStatus, + LastTransportError(JNIEnv *jni, const char* messagePtr, int errorStatus, void* (*alloc)(jint numBytes), void (*free)(void *buffer)); /** @@ -102,6 +107,7 @@ void operator delete(void* address, void* (*alloc)(jint numBytes), void (*free)(void *buffer)); private: + JNIEnv* m_jni; ThreadId_t m_treadId; // the thread Id const char* m_lastErrorMessage; // diagnostics for the last failed operation const char* m_lastErrorMessagePrefix; // diagnostics prefix for the last failed operation Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.cpp?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.cpp Wed May 7 04:41:26 2008 @@ -28,7 +28,136 @@ * Main module. */ +#ifndef USING_VMI +#define USING_VMI #include "SocketTransport_pd.h" +#include "j9socket.h" +#include "j9sock.h" + +typedef struct PortlibPTBuffers_struct +{ + struct PortlibPTBuffers_struct *next; /**< Next per thread buffer */ + struct PortlibPTBuffers_struct *previous; /**< Previous per thread buffer */ + I_32 platformErrorCode; /**< error code as reported by the OS */ + I_32 portableErrorCode; /**< error code translated to portable format by application */ + char *errorMessageBuffer; /**< last saved error message, either customized or from OS */ + U_32 errorMessageBufferSize; /**< error message buffer size */ + I_32 reportedErrorCode; /**< last reported error code */ + char *reportedMessageBuffer; /**< last reported error message, either customized or from OS */ + U_32 reportedMessageBufferSize; /**< reported message buffer size */ + j9fdset_t fdset; /**< file descriptor set */ + j9addrinfo_struct addr_info_hints; +} PortlibPTBuffers_struct; + +typedef struct PortlibPTBuffers_struct *PortlibPTBuffers_t; + +extern void *VMCALL j9port_tls_get (struct HyPortLibrary *portLibrary); + + +/** + * Returns the error status for the last failed operation. + */ +static int +GetLastErrorStatus(jdwpTransportEnv* env) +{ + internalEnv* ienv = (internalEnv*)env->functions->reserved1; + PORT_ACCESS_FROM_JAVAVM(ienv->jvm); + return j9error_last_error_number(); +} // GetLastErrorStatus + +/** + * Retrieves the number of milliseconds, substitute for the corresponding Win32 + * function. + */ +static long +GetTickCount(jdwpTransportEnv* env) +{ + internalEnv* ienv = (internalEnv*)env->functions->reserved1; + PORT_ACCESS_FROM_JAVAVM(ienv->jvm); + return (long)j9time_current_time_millis(); +} // GetTickCount + +/** + * Initializes critical section lock objects. + */ +static inline void +InitializeCriticalSections(jdwpTransportEnv* env) +{ + internalEnv* ienv = (internalEnv*)env->functions->reserved1; + j9thread_attach(NULL); + + UDATA flags = 0; + if (j9thread_monitor_init(&(ienv->readLock), 1) != 0) { + printf("initial error\n"); + } + + if (j9thread_monitor_init(&(ienv->sendLock), 1) != 0) { + printf("initial error\n"); + } + +} //InitializeCriticalSections() + +/** + * Releases all resources used by critical-section lock objects. + */ +static inline void +DeleteCriticalSections(jdwpTransportEnv* env) +{ + internalEnv* ienv = (internalEnv*)env->functions->reserved1; + + j9thread_attach(NULL); + j9thread_monitor_destroy(ienv->readLock); + j9thread_monitor_destroy(ienv->sendLock); +} //DeleteCriticalSections() + +/** + * Waits for ownership of the send critical-section object. + */ +static inline void +EnterCriticalSendSection(jdwpTransportEnv* env) +{ + internalEnv* ienv = (internalEnv*)env->functions->reserved1; + + j9thread_attach(NULL); + j9thread_monitor_enter(ienv->sendLock); +} //EnterCriticalSendSection() + +/** + * Waits for ownership of the read critical-section object. + */ +static inline void +EnterCriticalReadSection(jdwpTransportEnv* env) +{ + internalEnv* ienv = (internalEnv*)env->functions->reserved1; + + j9thread_attach(NULL); + j9thread_monitor_enter(ienv->readLock); +} //EnterCriticalReadSection() + +/** + * Releases ownership of the read critical-section object. + */ +static inline void +LeaveCriticalReadSection(jdwpTransportEnv* env) +{ + internalEnv* ienv = (internalEnv*)env->functions->reserved1; + + j9thread_attach(NULL); + j9thread_monitor_exit(ienv->readLock); +} //LeaveCriticalReadSection() + +/** + * Releases ownership of the send critical-section object. + */ +static inline void +LeaveCriticalSendSection(jdwpTransportEnv* env) +{ + internalEnv* ienv = (internalEnv*)env->functions->reserved1; + + j9thread_attach(NULL); + j9thread_monitor_exit(ienv->sendLock); +} //LeaveCriticalSendSection() + /** * This function sets into internalEnv struct message and status code of last transport error @@ -40,7 +169,9 @@ if (ienv->lastError != 0) { ienv->lastError->insertError(messagePtr, errorStatus); } else { - ienv->lastError = new(ienv->alloc, ienv->free) LastTransportError(messagePtr, errorStatus, ienv->alloc, ienv->free); + JNIEnv *jni; + ienv->jvm->GetEnv((void **)&jni, JNI_VERSION_1_4); + ienv->lastError = new(ienv->alloc, ienv->free) LastTransportError(jni, messagePtr, errorStatus, ienv->alloc, ienv->free); } return; } // SetLastTranError @@ -65,13 +196,72 @@ static const jint cycle = 1000; // wait cycle in milliseconds /** + * This function enable/disables socket blocking mode + */ +static bool +SetSocketBlockingMode(jdwpTransportEnv* env, j9socket_t sckt, bool isBlocked) +{ + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); + + jint ret = j9sock_set_nonblocking(sckt, isBlocked ? FALSE : TRUE); + if (ret != 0){ + SetLastTranError(env, "socket error", GetLastErrorStatus(env)); + return false; + } + return true; + +} // SetSocketBlockingMode() + +/** * This function is used to determine the read status of socket (in terms of select function). * The function avoids absolutely blocking select */ static jdwpTransportError -SelectRead(jdwpTransportEnv* env, SOCKET sckt, jlong deadline = 0) { +SelectRead(jdwpTransportEnv* env, j9socket_t sckt, jlong deadline = 0) { + internalEnv* ienv = (internalEnv*)env->functions->reserved1; + PORT_ACCESS_FROM_JAVAVM(ienv->jvm); +/* +#ifdef WIN32 + SOCKET socket = sckt->ipv4; +#else + SOCKET socket = sckt->sock; +#endif + deadline = deadline == 0 ? 1000 : deadline; + if (deadline >= 0) { + TIMEVAL tv = {(long)(deadline / 1000), (long)(deadline % 1000)}; + fd_set fdread; + FD_ZERO(&fdread); + FD_SET(socket, &fdread); - jlong currentTimeout = cycle; + int ret = select((int)(socket) + 1, &fdread,NULL, NULL, &tv); + if (ret < 0) { + int err = GetLastErrorStatus(env); + // ignore signal interruption + if (err != SOCKET_ERROR_EINTR) { + SetLastTranError(env, "socket error", err); + return JDWPTRANSPORT_ERROR_IO_ERROR; + } + } + if ((ret > 0) && (FD_ISSET(socket, &fdread))) { + return JDWPTRANSPORT_ERROR_NONE; //timeout is not occurred + } + } + SetLastTranError(env, "timeout occurred", 0); + return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred +*/ + jint ret = j9sock_select_read(sckt, (I_32) deadline / 1000 , (I_32) deadline % 1000, FALSE); + if (ret == 1){ + return JDWPTRANSPORT_ERROR_NONE; //timeout is not occurred + } + if (ret != J9PORT_ERROR_SOCKET_TIMEOUT){ + SetLastTranError(env, "socket error", ret); + return JDWPTRANSPORT_ERROR_IO_ERROR; + } + SetLastTranError(env, "timeout occurred", 0); + return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred + +/* jlong currentTimeout = cycle; while ((deadline == 0) || ((currentTimeout = (deadline - GetTickCount())) > 0)) { currentTimeout = currentTimeout < cycle ? currentTimeout : cycle; TIMEVAL tv = {(long)(currentTimeout / 1000), (long)(currentTimeout % 1000)}; @@ -81,7 +271,7 @@ int ret = select((int)sckt + 1, &fdread, NULL, NULL, &tv); if (ret == SOCKET_ERROR) { - int err = GetLastErrorStatus(); + int err = GetLastErrorStatus(env); // ignore signal interruption if (err != SOCKET_ERROR_EINTR) { SetLastTranError(env, "socket error", err); @@ -94,6 +284,7 @@ } SetLastTranError(env, "timeout occurred", 0); return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred +*/ } // SelectRead /** @@ -101,43 +292,98 @@ * The function avoids absolutely blocking select */ static jdwpTransportError -SelectSend(jdwpTransportEnv* env, SOCKET sckt, jlong deadline = 0) { +SelectSend(jdwpTransportEnv* env, j9socket_t sckt, jlong deadline = 0) { + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); - jlong currentTimeout = cycle; - while ((deadline == 0) || ((currentTimeout = (deadline - GetTickCount())) > 0)) { - currentTimeout = currentTimeout < cycle ? currentTimeout : cycle; - TIMEVAL tv = {(long)(currentTimeout / 1000), (long)(currentTimeout % 1000)}; + j9fdset_struct j9fdSet; + + I_32 secTime = (long)(deadline / 1000); + I_32 uTime = (long)(deadline % 1000); + + j9timeval_struct timeval; + + j9sock_fdset_zero(&j9fdSet); + j9sock_fdset_set(sckt,&j9fdSet); + + int ret = j9sock_timeval_init(secTime,uTime,&timeval); + + ret = j9sock_select(j9sock_fdset_size(sckt),NULL,&j9fdSet,NULL,&timeval); + + if (ret > 0){ + return JDWPTRANSPORT_ERROR_NONE; //timeout is not occurred + } + if (ret != J9PORT_ERROR_SOCKET_TIMEOUT){ + SetLastTranError(env, "socket error", ret); + return JDWPTRANSPORT_ERROR_IO_ERROR; + } + SetLastTranError(env, "timeout occurred", 0); + return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred + + //jlong currentTimeout = cycle; + +// leave a workaround here, wait for new portlib for select APIs +/* #ifdef WIN32 + SOCKET socket = sckt->ipv4; +#else + SOCKET socket = sckt->sock; +#endif + deadline = deadline == 0 ? 100 : deadline; + if (deadline >= 0) { + TIMEVAL tv = {(long)(deadline / 1000), (long)(deadline % 1000)}; fd_set fdwrite; FD_ZERO(&fdwrite); - FD_SET(sckt, &fdwrite); + FD_SET(socket, &fdwrite); - int ret = select((int)sckt + 1, NULL, &fdwrite, NULL, &tv); - if (ret == SOCKET_ERROR) { - int err = GetLastErrorStatus(); + int ret = select((int)(socket) + 1, NULL, &fdwrite, NULL, &tv); + if (ret < 0) { + int err = GetLastErrorStatus(env); // ignore signal interruption if (err != SOCKET_ERROR_EINTR) { SetLastTranError(env, "socket error", err); return JDWPTRANSPORT_ERROR_IO_ERROR; } } - if ((ret > 0) && (FD_ISSET(sckt, &fdwrite))) { + if ((ret > 0) && (FD_ISSET(socket, &fdwrite))) { return JDWPTRANSPORT_ERROR_NONE; //timeout is not occurred } } SetLastTranError(env, "timeout occurred", 0); return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred -} // SelectRead + */ +} // SelectSend /** * This function sends data on a connected socket */ static jdwpTransportError -SendData(jdwpTransportEnv* env, SOCKET sckt, const char* data, int dataLength, jlong deadline = 0) +SendData(jdwpTransportEnv* env, j9socket_t sckt, const char* data, int dataLength, jlong deadline = 0) { long left = dataLength; long off = 0; int ret; + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); + + // Check if block + while (left > 0){ + jdwpTransportError err = SelectSend(env, sckt, deadline); + if (err != JDWPTRANSPORT_ERROR_NONE) { + return err; + } + + ret = j9sock_write (sckt, (U_8 *)data+off, left, J9SOCK_NOFLAGS); + if (ret < 0){ + SetLastTranError(env, "socket error", ret); + return JDWPTRANSPORT_ERROR_IO_ERROR; + } + left -= ret; + off += ret; + } + return JDWPTRANSPORT_ERROR_NONE; + + /* while (left > 0) { jdwpTransportError err = SelectSend(env, sckt, deadline); if (err != JDWPTRANSPORT_ERROR_NONE) { @@ -145,7 +391,7 @@ } ret = send(sckt, (data + off), left, 0); if (ret == SOCKET_ERROR) { - int err = GetLastErrorStatus(); + int err = GetLastErrorStatus(env); // ignore signal interruption if (err != SOCKET_ERROR_EINTR) { SetLastTranError(env, "socket error", err); @@ -155,15 +401,18 @@ left -= ret; off += ret; } //while - return JDWPTRANSPORT_ERROR_NONE; + return JDWPTRANSPORT_ERROR_NONE;*/ } //SendData /** * This function receives data from a connected socket */ static jdwpTransportError -ReceiveData(jdwpTransportEnv* env, SOCKET sckt, char* buffer, int dataLength, jlong deadline = 0, int* readByte = 0) +ReceiveData(jdwpTransportEnv* env, j9socket_t sckt, U_8 * buffer, int dataLength, jlong deadline = 0, int* readByte = 0) { + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); + long left = dataLength; long off = 0; int ret; @@ -177,9 +426,34 @@ if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } + + ret = j9sock_read(sckt, (U_8 *) (buffer + off), left, J9SOCK_NOFLAGS); + + if (ret < 0) { + SetLastTranError(env, "data receiving failed", ret); + return JDWPTRANSPORT_ERROR_IO_ERROR; + } + if (ret == 0) { + SetLastTranError(env, "premature EOF", J9SOCK_NOFLAGS); + return JDWPTRANSPORT_ERROR_IO_ERROR; + } + left -= ret; + off += ret; + if (readByte != 0) { + *readByte = off; + } + } //while + return JDWPTRANSPORT_ERROR_NONE; + +/* + while (left > 0) { + jdwpTransportError err = SelectRead(env, sckt, deadline); + if (err != JDWPTRANSPORT_ERROR_NONE) { + return err; + } ret = recv(sckt, (buffer + off), left, 0); if (ret == SOCKET_ERROR) { - int err = GetLastErrorStatus(); + int err = GetLastErrorStatus(env); // ignore signal interruption if (err != SOCKET_ERROR_EINTR) { SetLastTranError(env, "data receiving failed", err); @@ -196,52 +470,35 @@ *readByte = off; } } //while - return JDWPTRANSPORT_ERROR_NONE; + return JDWPTRANSPORT_ERROR_NONE;*/ } // ReceiveData /** - * This function enable/disables socket blocking mode - */ -static bool -SetSocketBlockingMode(jdwpTransportEnv* env, SOCKET sckt, bool isBlocked) -{ - unsigned long ul = isBlocked ? 0 : 1; - if (ioctlsocket(sckt, FIONBIO, &ul) == SOCKET_ERROR) { - SetLastTranError(env, "socket error", GetLastErrorStatus()); - return false; - } - return true; -} // SetSocketBlockingMode() - -/** * This function performes handshake procedure */ static jdwpTransportError -CheckHandshaking(jdwpTransportEnv* env, SOCKET sckt, jlong handshakeTimeout) +CheckHandshaking(jdwpTransportEnv* env, j9socket_t sckt, jlong handshakeTimeout) { const char* handshakeString = "JDWP-Handshake"; - char receivedString[14]; //length of "JDWP-Handshake" - - jlong deadline = (handshakeTimeout == 0) ? 0 : (jlong)GetTickCount() + handshakeTimeout; + U_8 receivedString[14]; //length of "JDWP-Handshake" jdwpTransportError err; - err = SendData(env, sckt, handshakeString, (int)strlen(handshakeString), deadline); + err = SendData(env, sckt, handshakeString, (int)strlen(handshakeString), handshakeTimeout); if (err != JDWPTRANSPORT_ERROR_NONE) { SetLastTranErrorMessagePrefix(env, "'JDWP-Handshake' sending error: "); return err; } - - err = ReceiveData(env, sckt, receivedString, (int)strlen(handshakeString), deadline); + + err = ReceiveData(env, sckt, receivedString, (int)strlen(handshakeString), handshakeTimeout); + if (err != JDWPTRANSPORT_ERROR_NONE) { SetLastTranErrorMessagePrefix(env, "'JDWP-Handshake' receiving error: "); return err; } - if (memcmp(receivedString, handshakeString, 14) != 0) { SetLastTranError(env, "handshake error, 'JDWP-Handshake' is not received", 0); return JDWPTRANSPORT_ERROR_IO_ERROR; } - return JDWPTRANSPORT_ERROR_NONE; }// CheckHandshaking @@ -249,42 +506,53 @@ * This function decodes address and populates sockaddr_in structure */ static jdwpTransportError -DecodeAddress(jdwpTransportEnv* env, const char *address, struct sockaddr_in *sa, bool isServer) +DecodeAddress(jdwpTransportEnv* env, const char *address, j9sockaddr_t sa, bool isServer) { - memset(sa, 0, sizeof(struct sockaddr_in)); - sa->sin_family = AF_INET; + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); + char * localhost = "127.0.0.1"; + char * anyhost = "0.0.0.0"; +// memset(sa, 0, sizeof(struct sockaddr_in)); +// sa->sin_family = AF_INET; if ((address == 0) || (*address == 0)) { //empty address - sa->sin_addr.s_addr = isServer ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"); - sa->sin_port = 0; + j9sock_sockaddr(sa, isServer ? anyhost : localhost, 0); +// sa->sin_addr.s_addr = isServer ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"); +// sa->sin_port = 0; return JDWPTRANSPORT_ERROR_NONE; } const char* colon = strchr(address, ':'); if (colon == 0) { //address is like "port" - sa->sin_port = htons((u_short)atoi(address)); - sa->sin_addr.s_addr = isServer ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"); + j9sock_sockaddr(sa, isServer ? anyhost : localhost, j9sock_htons((U_16)atoi(address))); + //sa->sin_port = htons((u_short)atoi(address)); + //sa->sin_addr.s_addr = isServer ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"); } else { //address is like "host:port" - sa->sin_port = htons((u_short)atoi(colon + 1)); - + //sa->sin_port = htons((u_short)atoi(colon + 1)); char *hostName = (char*)(((internalEnv*)env->functions->reserved1) ->alloc)((jint)(colon - address + 1)); if (hostName == 0) { SetLastTranError(env, "out of memory", 0); return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY; } - memcpy(hostName, address, colon - address); + memcpy(hostName, address, colon - address); hostName[colon - address] = '\0'; - sa->sin_addr.s_addr = inet_addr(hostName); - if (sa->sin_addr.s_addr == INADDR_NONE) { + int ret = j9sock_sockaddr(sa, hostName, j9sock_htons((U_16)atoi(colon + 1))); + if (ret != 0){ + SetLastTranError(env, "unable to resolve host name", 0); + (((internalEnv*)env->functions->reserved1)->free)(hostName); + return JDWPTRANSPORT_ERROR_IO_ERROR; + } + /* sa->sin_addr.s_addr = inet_addr(hostName); + if (ret != 0) { struct hostent *host = gethostbyname(hostName); if (host == 0) { SetLastTranError(env, "unable to resolve host name", 0); (((internalEnv*)env->functions->reserved1)->free)(hostName); return JDWPTRANSPORT_ERROR_IO_ERROR; } - memcpy(&(sa->sin_addr), host->h_addr_list[0], host->h_length); - } //if + //TODO delete this memcpy(&(sa->sin_addr), host->h_addr_list[0], host->h_length); + } //if*/ (((internalEnv*)env->functions->reserved1)->free)(hostName); } //if return JDWPTRANSPORT_ERROR_NONE; @@ -299,9 +567,8 @@ { memset(capabilitiesPtr, 0, sizeof(JDWPTransportCapabilities)); capabilitiesPtr->can_timeout_attach = 1; - capabilitiesPtr->can_timeout_accept = 1; + capabilitiesPtr->can_timeout_accept = 1; capabilitiesPtr->can_timeout_handshake = 1; - return JDWPTRANSPORT_ERROR_NONE; } //TCPIPSocketTran_GetCapabilities @@ -310,46 +577,89 @@ */ static jdwpTransportError JNICALL TCPIPSocketTran_Close(jdwpTransportEnv* env) -{ - SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket == INVALID_SOCKET) { +{ + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); + j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket == NULL) { return JDWPTRANSPORT_ERROR_NONE; } - ((internalEnv*)env->functions->reserved1)->envClientSocket = INVALID_SOCKET; + ((internalEnv*)env->functions->reserved1)->envClientSocket = NULL; + if (j9sock_socketIsValid(envClientSocket)==0){ + return JDWPTRANSPORT_ERROR_NONE; + } int err; - err = shutdown(envClientSocket, SD_BOTH); + err = j9sock_shutdown_input(envClientSocket); + if (err == 0){ + err = j9sock_shutdown_output(envClientSocket); + } + if (err != 0) { + SetLastTranError(env, "shutdown socket failed", GetLastErrorStatus(env)); + return JDWPTRANSPORT_ERROR_IO_ERROR; + } +/*#ifdef WIN32 + SOCKET socket = envClientSocket->ipv4; + err = closesocket(socket); +#else + SOCKET socket = envClientSocket->sock; + err = close(socket); +#endif*/ + err = j9sock_close(&envClientSocket); + + if (err != 0) { + SetLastTranError(env, "close socket failed", GetLastErrorStatus(env)); + return JDWPTRANSPORT_ERROR_IO_ERROR; + } + return JDWPTRANSPORT_ERROR_NONE; + +/* err = shutdown(envClientSocket, SD_BOTH); if (err == SOCKET_ERROR) { - SetLastTranError(env, "close socket failed", GetLastErrorStatus()); + SetLastTranError(env, "close socket failed", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_IO_ERROR; } err = closesocket(envClientSocket); if (err == SOCKET_ERROR) { - SetLastTranError(env, "close socket failed", GetLastErrorStatus()); + SetLastTranError(env, "close socket failed", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_IO_ERROR; } - return JDWPTRANSPORT_ERROR_NONE; + return JDWPTRANSPORT_ERROR_NONE;*/ } //TCPIPSocketTran_Close /** * This function sets socket options SO_REUSEADDR and TCP_NODELAY */ static bool -SetSocketOptions(jdwpTransportEnv* env, SOCKET sckt) +SetSocketOptions(jdwpTransportEnv* env, j9socket_t sckt) { - BOOL isOn = TRUE; - if (setsockopt(sckt, SOL_SOCKET, SO_REUSEADDR, (const char*)&isOn, sizeof(isOn)) == SOCKET_ERROR) { - SetLastTranError(env, "setsockopt(SO_REUSEADDR) failed", GetLastErrorStatus()); + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); + + BOOLEAN isOn = TRUE; + + if (j9sock_setopt_bool(sckt, J9_SOL_SOCKET, J9_SO_REUSEADDR, &isOn) != 0){ + SetLastTranError(env, "setsockopt(SO_REUSEADDR) failed", GetLastErrorStatus(env)); return false; } - if (setsockopt(sckt, IPPROTO_TCP, TCP_NODELAY, (const char*)&isOn, sizeof(isOn)) == SOCKET_ERROR) { - SetLastTranError(env, "setsockopt(TCPNODELAY) failed", GetLastErrorStatus()); + if (j9sock_setopt_bool(sckt, J9_IPPROTO_IP, J9_TCP_NODELAY, &isOn) != 0) { + SetLastTranError(env, "setsockopt(TCPNODELAY) failed", GetLastErrorStatus(env)); return false; } + return true; + +/* if (setsockopt(sckt, SOL_SOCKET, SO_REUSEADDR, (const char*)&isOn, sizeof(isOn)) == SOCKET_ERROR) { + SetLastTranError(env, "setsockopt(SO_REUSEADDR) failed", GetLastErrorStatus(env)); + return false; + } + if (setsockopt(sckt, IPPROTO_TCP, TCP_NODELAY, (const char*)&isOn, sizeof(isOn)) == SOCKET_ERROR) { + SetLastTranError(env, "setsockopt(TCPNODELAY) failed", GetLastErrorStatus(env)); + return false; + } + return true;*/ } // SetSocketOptions() /** @@ -359,6 +669,12 @@ TCPIPSocketTran_Attach(jdwpTransportEnv* env, const char* address, jlong attachTimeout, jlong handshakeTimeout) { + internalEnv *ienv = (internalEnv*)env->functions->reserved1; + PORT_ACCESS_FROM_JAVAVM(ienv->jvm); + + j9socket_t clientSocket; + j9sockaddr_struct serverSockAddr; + if ((address == 0) || (*address == 0)) { SetLastTranError(env, "address is missing", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; @@ -374,27 +690,27 @@ return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; } - SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket != INVALID_SOCKET) { + j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket != NULL) { SetLastTranError(env, "there is already an open connection to the debugger", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; - if (envServerSocket != INVALID_SOCKET) { + j9socket_t envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; + if (envServerSocket != NULL) { SetLastTranError(env, "transport is currently in listen mode", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - struct sockaddr_in serverSockAddr; jdwpTransportError res = DecodeAddress(env, address, &serverSockAddr, false); if (res != JDWPTRANSPORT_ERROR_NONE) { return res; } - SOCKET clientSocket = socket(AF_INET, SOCK_STREAM, 0); - if (clientSocket == INVALID_SOCKET) { - SetLastTranError(env, "unable to create socket", GetLastErrorStatus()); + int ret = j9sock_socket(&clientSocket,J9SOCK_AFINET, J9SOCK_STREAM, J9SOCK_DEFPROTOCOL); + // socket(AF_INET, SOCK_STREAM, 0); + if (ret != 0) { + SetLastTranError(env, "unable to create socket", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_IO_ERROR; } @@ -406,43 +722,49 @@ if (!SetSocketBlockingMode(env, clientSocket, true)) { return JDWPTRANSPORT_ERROR_IO_ERROR; } - int err = connect(clientSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr)); - if (err == SOCKET_ERROR) { - SetLastTranError(env, "connection failed", GetLastErrorStatus()); + int err = j9sock_connect(clientSocket, &serverSockAddr); + //int err = connect(clientSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr)); + if (err != 0 ) { + SetLastTranError(env, "connection failed", GetLastErrorStatus(env)); SetSocketBlockingMode(env, clientSocket, false); return JDWPTRANSPORT_ERROR_IO_ERROR; - } + } if (!SetSocketBlockingMode(env, clientSocket, false)) { return JDWPTRANSPORT_ERROR_IO_ERROR; - } + } } else { if (!SetSocketBlockingMode(env, clientSocket, false)) { return JDWPTRANSPORT_ERROR_IO_ERROR; } - int err = connect(clientSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr)); - if (err == SOCKET_ERROR) { - if (GetLastErrorStatus() != SOCKETWOULDBLOCK) { - SetLastTranError(env, "connection failed", GetLastErrorStatus()); + int err = j9sock_connect(clientSocket, &serverSockAddr); + if (err != 0) { + if (err != J9PORT_ERROR_SOCKET_WOULDBLOCK) { + SetLastTranError(env, "connection failed", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_IO_ERROR; - } else { - fd_set fdwrite; + } else { + int ret = SelectSend(env, clientSocket, handshakeTimeout); + if (ret == JDWPTRANSPORT_ERROR_NONE){ + return JDWPTRANSPORT_ERROR_NONE; + } + return JDWPTRANSPORT_ERROR_IO_ERROR; +//TODO delele this selectWrite + /*fd_set fdwrite; FD_ZERO(&fdwrite); FD_SET(clientSocket, &fdwrite); TIMEVAL tv = {(long)(attachTimeout / 1000), (long)(attachTimeout % 1000)}; int ret = select((int)clientSocket + 1, NULL, &fdwrite, NULL, &tv); if (ret == SOCKET_ERROR) { - SetLastTranError(env, "socket error", GetLastErrorStatus()); + SetLastTranError(env, "socket error", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_IO_ERROR; } if ((ret != 1) || !(FD_ISSET(clientSocket, &fdwrite))) { SetLastTranError(env, "timeout occurred", 0); return JDWPTRANSPORT_ERROR_IO_ERROR; - } + }*/ } } } - EnterCriticalSendSection(env); EnterCriticalReadSection(env); ((internalEnv*)env->functions->reserved1)->envClientSocket = clientSocket; @@ -453,7 +775,6 @@ TCPIPSocketTran_Close(env); return res; } - return JDWPTRANSPORT_ERROR_NONE; } //TCPIPSocketTran_Attach @@ -464,28 +785,32 @@ TCPIPSocketTran_StartListening(jdwpTransportEnv* env, const char* address, char** actualAddress) { - SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket != INVALID_SOCKET) { + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); + + j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket != NULL) { SetLastTranError(env, "there is already an open connection to the debugger", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; - if (envServerSocket != INVALID_SOCKET) { + j9socket_t envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; + if (envServerSocket != NULL) { SetLastTranError(env, "transport is currently in listen mode", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } jdwpTransportError res; - struct sockaddr_in serverSockAddr; + j9sockaddr_struct serverSockAddr; res = DecodeAddress(env, address, &serverSockAddr, true); if (res != JDWPTRANSPORT_ERROR_NONE) { return res; } - SOCKET serverSocket = socket(AF_INET, SOCK_STREAM, 0); - if (serverSocket == INVALID_SOCKET) { - SetLastTranError(env, "unable to create socket", GetLastErrorStatus()); + j9socket_t serverSocket; + int ret = j9sock_socket(&serverSocket,J9SOCK_AFINET, J9SOCK_STREAM, J9SOCK_DEFPROTOCOL); //socket(AF_INET, SOCK_STREAM, 0); + if (ret != 0) { + SetLastTranError(env, "unable to create socket", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_IO_ERROR; } @@ -495,15 +820,16 @@ int err; - err = bind(serverSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr)); - if (err == SOCKET_ERROR) { - SetLastTranError(env, "binding to port failed", GetLastErrorStatus()); + err = j9sock_bind (serverSocket, &serverSockAddr); + // bind(serverSocket, (struct sockaddr *)&serverSockAddr, sizeof(serverSockAddr)); + if (err != 0 ) { + SetLastTranError(env, "binding to port failed", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - err = listen(serverSocket, SOMAXCONN); - if (err == SOCKET_ERROR) { - SetLastTranError(env, "listen start failed", GetLastErrorStatus()); + err = j9sock_listen(serverSocket, J9SOCK_MAXCONN); + if (err != 0) { + SetLastTranError(env, "listen start failed", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } @@ -513,10 +839,9 @@ ((internalEnv*)env->functions->reserved1)->envServerSocket = serverSocket; - socklen_t len = sizeof(serverSockAddr); - err = getsockname(serverSocket, (struct sockaddr *)&serverSockAddr, &len); - if (err == SOCKET_ERROR) { - SetLastTranError(env, "socket error", GetLastErrorStatus()); + err = j9sock_getsockname(serverSocket, &serverSockAddr); + if (err != 0) { + SetLastTranError(env, "socket error", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } @@ -547,7 +872,8 @@ SetLastTranError(env, "out of memory", 0); return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY; } - sprintf(retAddress, "%d", ntohs(serverSockAddr.sin_port)); + // print server port + sprintf(retAddress, "%d",j9sock_sockaddr_port(&serverSockAddr)); *actualAddress = retAddress; @@ -560,17 +886,27 @@ static jdwpTransportError JNICALL TCPIPSocketTran_StopListening(jdwpTransportEnv* env) { - SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; - if (envServerSocket == INVALID_SOCKET) { + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); + + j9socket_t envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; + if (envServerSocket == NULL) { return JDWPTRANSPORT_ERROR_NONE; } - - if (closesocket(envServerSocket) == SOCKET_ERROR) { - SetLastTranError(env, "close socket failed", GetLastErrorStatus()); +/*#ifdef WIN32 + SOCKET socket = envServerSocket->ipv4; + int err = closesocket(socket); +#else + SOCKET socket = envServerSocket->sock; + int err = close(socket); +#endif */ + int err = j9sock_close(&envServerSocket); + if (err != 0) { + SetLastTranError(env, "close socket failed", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_IO_ERROR; } - ((internalEnv*)env->functions->reserved1)->envServerSocket = INVALID_SOCKET; + ((internalEnv*)env->functions->reserved1)->envServerSocket = NULL; return JDWPTRANSPORT_ERROR_NONE; } //TCPIPSocketTran_StopListening @@ -582,6 +918,9 @@ TCPIPSocketTran_Accept(jdwpTransportEnv* env, jlong acceptTimeout, jlong handshakeTimeout) { + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); + if (acceptTimeout < 0) { SetLastTranError(env, "acceptTimeout timeout is negative", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; @@ -592,35 +931,43 @@ return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; } - SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket != INVALID_SOCKET) { + j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket != NULL) { SetLastTranError(env, "there is already an open connection to the debugger", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - SOCKET envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; - if (envServerSocket == INVALID_SOCKET) { + j9socket_t envServerSocket = ((internalEnv*)env->functions->reserved1)->envServerSocket; + if (envServerSocket == NULL) { SetLastTranError(env, "transport is not currently in listen mode", 0); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; } - struct sockaddr serverSockAddr; - socklen_t len = sizeof(serverSockAddr); - int res = getsockname(envServerSocket, &serverSockAddr, &len); + j9sockaddr_struct serverSockAddr; +/* int res = j9sock_getpeername(envServerSocket, &serverSockAddr); if (res == SOCKET_ERROR) { - SetLastTranError(env, "connection failed", GetLastErrorStatus()); + SetLastTranError(env, "connection failed", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_IO_ERROR; - } + }*/ - jlong deadline = (acceptTimeout == 0) ? 0 : (jlong)GetTickCount() + acceptTimeout; - jdwpTransportError err = SelectRead(env, envServerSocket, deadline); - if (err != JDWPTRANSPORT_ERROR_NONE) { - return err; + //jlong deadline = (acceptTimeout == 0) ? 0 : (jlong)GetTickCount() + acceptTimeout; + I_32 ret = SelectRead(env, envServerSocket, acceptTimeout); + //I_32 ret = j9sock_select_read(envServerSocket, (I_32)acceptTimeout/1000, (I_32)acceptTimeout%1000, TRUE); + + if (ret != JDWPTRANSPORT_ERROR_NONE){ + if (ret != J9PORT_ERROR_SOCKET_TIMEOUT){ + SetLastTranError(env, "socket error", ret); + return JDWPTRANSPORT_ERROR_IO_ERROR; + } + SetLastTranError(env, "timeout occurred", 0); + return JDWPTRANSPORT_ERROR_TIMEOUT; //timeout occurred } - SOCKET clientSocket = accept(envServerSocket, &serverSockAddr, &len); - if (clientSocket == INVALID_SOCKET) { - SetLastTranError(env, "socket accept failed", GetLastErrorStatus()); + j9socket_t clientSocket; + ret = j9sock_accept(envServerSocket, &serverSockAddr, &clientSocket); + + if (ret != 0) { + SetLastTranError(env, "socket accept failed", GetLastErrorStatus(env)); return JDWPTRANSPORT_ERROR_IO_ERROR; } @@ -631,15 +978,13 @@ EnterCriticalSendSection(env); EnterCriticalReadSection(env); ((internalEnv*)env->functions->reserved1)->envClientSocket = clientSocket; - - err = CheckHandshaking(env, clientSocket, (long)handshakeTimeout); + jdwpTransportError err = CheckHandshaking(env, clientSocket, (long)handshakeTimeout); LeaveCriticalReadSection(env); LeaveCriticalSendSection(env); if (err != JDWPTRANSPORT_ERROR_NONE) { TCPIPSocketTran_Close(env); return err; } - return JDWPTRANSPORT_ERROR_NONE; } //TCPIPSocketTran_Accept @@ -649,8 +994,8 @@ static jboolean JNICALL TCPIPSocketTran_IsOpen(jdwpTransportEnv* env) { - SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket == INVALID_SOCKET) { + j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket == NULL) { return JNI_FALSE; } return JNI_TRUE; @@ -660,12 +1005,15 @@ * This function read packet */ static jdwpTransportError -ReadPacket(jdwpTransportEnv* env, SOCKET envClientSocket, jdwpPacket* packet) +ReadPacket(jdwpTransportEnv* env, j9socket_t envClientSocket, jdwpPacket* packet) { + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); + jdwpTransportError err; int length; int readBytes = 0; - err = ReceiveData(env, envClientSocket, (char *)&length, sizeof(jint), 0, &readBytes); + err = ReceiveData(env, envClientSocket, (U_8 *)&length, sizeof(jint), 0, &readBytes); if (err != JDWPTRANSPORT_ERROR_NONE) { if (readBytes == 0) { packet->type.cmd.len = 0; @@ -673,36 +1021,35 @@ } return err; } - - packet->type.cmd.len = (jint)ntohl(length); + packet->type.cmd.len = (jint)j9sock_ntohl(length); int id; - err = ReceiveData(env, envClientSocket, (char *)&(id), sizeof(jint)); + err = ReceiveData(env, envClientSocket, (U_8 *)&(id), sizeof(jint)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } - packet->type.cmd.id = (jint)ntohl(id); + packet->type.cmd.id = (jint)j9sock_ntohl(id); - err = ReceiveData(env, envClientSocket, (char *)&(packet->type.cmd.flags), sizeof(jbyte)); + err = ReceiveData(env, envClientSocket, (U_8 *)&(packet->type.cmd.flags), sizeof(jbyte)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } if (packet->type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY) { - u_short errorCode; - err = ReceiveData(env, envClientSocket, (char*)&(errorCode), sizeof(jshort)); + int errorCode; + err = ReceiveData(env, envClientSocket, (U_8*)&(errorCode), sizeof(jshort)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } - packet->type.reply.errorCode = (jshort)ntohs(errorCode); + packet->type.reply.errorCode = (jshort)j9sock_ntohs(errorCode); } else { - err = ReceiveData(env, envClientSocket, (char*)&(packet->type.cmd.cmdSet), sizeof(jbyte)); + err = ReceiveData(env, envClientSocket, (U_8*)&(packet->type.cmd.cmdSet), sizeof(jbyte)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } - err = ReceiveData(env, envClientSocket, (char*)&(packet->type.cmd.cmd), sizeof(jbyte)); + err = ReceiveData(env, envClientSocket, (U_8*)&(packet->type.cmd.cmd), sizeof(jbyte)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; } @@ -720,7 +1067,7 @@ SetLastTranError(env, "out of memory", 0); return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY; } - err = ReceiveData(env, envClientSocket, (char *)packet->type.cmd.data, dataLength); + err = ReceiveData(env, envClientSocket, (U_8 *)packet->type.cmd.data, dataLength); if (err != JDWPTRANSPORT_ERROR_NONE) { (((internalEnv*)env->functions->reserved1)->free)(packet->type.cmd.data); return err; @@ -740,8 +1087,8 @@ return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; } - SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket == INVALID_SOCKET) { + j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket == NULL) { SetLastTranError(env, "there isn't an open connection to a debugger", 0); LeaveCriticalReadSection(env); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE ; @@ -757,8 +1104,10 @@ * This function implements jdwpTransportEnv::WritePacket */ static jdwpTransportError -WritePacket(jdwpTransportEnv* env, SOCKET envClientSocket, const jdwpPacket* packet) +WritePacket(jdwpTransportEnv* env, j9socket_t envClientSocket, const jdwpPacket* packet) { + JavaVM *vm = ((internalEnv*)env->functions->reserved1)->jvm; + PORT_ACCESS_FROM_JAVAVM(vm); int packetLength = packet->type.cmd.len; if (packetLength < 11) { SetLastTranError(env, "invalid packet length", 0); @@ -772,7 +1121,7 @@ } int dataLength = packetLength - 11; - packetLength = htonl(packetLength); + packetLength = j9sock_htonl(packetLength); jdwpTransportError err; err = SendData(env, envClientSocket, (char*)&packetLength, sizeof(jint)); @@ -780,7 +1129,7 @@ return err; } - int id = htonl(packet->type.cmd.id); + int id = j9sock_htonl (packet->type.cmd.id); err = SendData(env, envClientSocket, (char*)&id, sizeof(jint)); if (err != JDWPTRANSPORT_ERROR_NONE) { @@ -793,7 +1142,7 @@ } if (packet->type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY) { - u_short errorCode = htons(packet->type.reply.errorCode); + int errorCode = htons(packet->type.reply.errorCode); err = SendData(env, envClientSocket, (char*)&errorCode, sizeof(jshort)); if (err != JDWPTRANSPORT_ERROR_NONE) { return err; @@ -830,10 +1179,10 @@ return JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT; } - SOCKET envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; - if (envClientSocket == INVALID_SOCKET) { + j9socket_t envClientSocket = ((internalEnv*)env->functions->reserved1)->envClientSocket; + if (envClientSocket == NULL) { SetLastTranError(env, "there isn't an open connection to a debugger", 0); - LeaveCriticalSendSection(env); + //LeaveCriticalSendSection(env); return JDWPTRANSPORT_ERROR_ILLEGAL_STATE; } @@ -850,6 +1199,7 @@ TCPIPSocketTran_GetLastError(jdwpTransportEnv* env, char** message) { *message = ((internalEnv*)env->functions->reserved1)->lastError->GetLastErrorMessage(); + if (*message == 0) { return JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE; } @@ -875,8 +1225,8 @@ iEnv->alloc = callback->alloc; iEnv->free = callback->free; iEnv->lastError = 0; - iEnv->envClientSocket = INVALID_SOCKET; - iEnv->envServerSocket = INVALID_SOCKET; + iEnv->envClientSocket = NULL; + iEnv->envServerSocket = NULL; jdwpTransportNativeInterface_* envTNI = (jdwpTransportNativeInterface_*)callback ->alloc(sizeof(jdwpTransportNativeInterface_)); @@ -931,4 +1281,4 @@ unLoadFree((void*)(*env)->functions); unLoadFree((void*)(*env)); } //jdwpTransport_UnLoad - +#endif Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.h?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/transport/dt_socket/SocketTransport.h Wed May 7 04:41:26 2008 @@ -33,6 +33,13 @@ #ifndef _SOCKETTRANSPORT_H #define _SOCKETTRANSPORT_H +#include "SocketTransport_pd.h" +#include "j9thread.h" +//#include "jni.h" + +typedef j9thread_monitor_t CriticalSection; +//typedef jobject CriticalSection; + struct internalEnv { JavaVM *jvm; // the JNI invocation interface, provided // by the agent @@ -40,8 +47,8 @@ // provided by the agent void (*free)(void *buffer); // the function deallocating an area of memory, // provided by the agent - SOCKET envClientSocket; // the client socket, INVALID_SOCKET if closed - SOCKET envServerSocket; // the server socket, INVALID_SOCKET if closed + j9socket_t envClientSocket; // the client socket, INVALID_SOCKET if closed + j9socket_t envServerSocket; // the server socket, INVALID_SOCKET if closed LastTransportError* lastError; // last errors CriticalSection readLock; // the critical-section lock object for socket // read operations Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/core/TransportManager_pd.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/core/TransportManager_pd.cpp?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/core/TransportManager_pd.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/core/TransportManager_pd.cpp Wed May 7 04:41:26 2008 @@ -134,7 +134,7 @@ JDWP_TRACE_PROG("StartDebugger: launched: pid=" << pid); } } - +/* ProcPtr jdwp::GetProcAddress(LoadedLibraryHandler libHandler, const char* procName) { JDWP_TRACE_ENTRY("GetProcAddress(" << libHandler << ',' << JDWP_CHECK_NULL(procName) << ')'); @@ -148,6 +148,7 @@ return res; } + bool jdwp::FreeLibrary(LoadedLibraryHandler libHandler) { JDWP_TRACE_ENTRY("FreeLibrary(" << libHandler << ')'); @@ -184,4 +185,4 @@ JDWP_TRACE_PROG("LoadTransport: transport library " << transportFullName << " loaded"); } return res; -} +}*/ Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/makefile URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/makefile?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/makefile (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/agent/makefile Wed May 7 04:41:26 2008 @@ -28,8 +28,6 @@ INCLUDES += -I$(CMNAGENT)commands -I$(CMNAGENT)core \ -I$(COMMON)generic -Icore -INCLUDES := -I../../../include $(INCLUDES) - LDFLAGS += -lstdc++ BUILDFILES = \ @@ -53,10 +51,9 @@ $(CMNAGENT)core/ObjectManager.o $(CMNAGENT)core/OptionParser.o $(CMNAGENT)core/PacketDispatcher.o \ $(CMNAGENT)core/PacketParser.o $(CMNAGENT)core/RequestManager.o $(CMNAGENT)core/RequestModifier.o \ $(CMNAGENT)core/ThreadManager.o $(CMNAGENT)core/TransportManager.o $(CMNAGENT)core/AgentManager.o \ - $(CMNAGENT)core/CallBacks.o \ core/TransportManager_pd.o -MDLLIBFILES = +MDLLIBFILES = $(LIBPATH)libj9vmi.a DLLNAME = ../libjdwp.so Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/dt_socket/SocketTransport_pd.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/dt_socket/SocketTransport_pd.h?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/dt_socket/SocketTransport_pd.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/dt_socket/SocketTransport_pd.h Wed May 7 04:41:26 2008 @@ -33,24 +33,19 @@ #define _SOCKETTRANSPORT_PD_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "LastTransportError.h" +#include "vmi.h" +#include "j9thread.h" +#include "j9socket.h" +#include "portsock.h" +#include "j9port.h" + +//#include "j9sock.h" +#include "jni.h" -typedef pthread_mutex_t CriticalSection; +//typedef pthread_mutex_t CriticalSection; typedef int SOCKET; -typedef pthread_t ThreadId_t; +//typedef pthread_t ThreadId_t; #include "jdwpTransport.h" #include "LastTransportError.h" @@ -59,118 +54,8 @@ typedef timeval TIMEVAL; typedef int BOOL; -const int TRUE = 1; +const int SOCKETWOULDBLOCK = J9PORT_ERROR_SOCKET_WOULDBLOCK; +const int SOCKET_ERROR_EINTR = J9PORT_ERROR_SOCKET_INTERRUPTED; const int SOCKET_ERROR = -1; -const int SOCKET_ERROR_EINTR = EINTR; -const int INVALID_SOCKET = -1; -const int SD_BOTH = 2; -const int SOCKETWOULDBLOCK = EINPROGRESS; - -/** - * Returns the error status for the last failed operation. - */ -static inline int -GetLastErrorStatus() -{ - return errno; -} - -/** - * Retrieves the number of milliseconds, substitute for the corresponding Win32 - * function. - */ -static inline long -GetTickCount(void) -{ - struct timeval t; - gettimeofday(&t, 0); - return t.tv_sec * 1000 + (t.tv_usec/1000); -} - -/** - * Closes socket, substitute for the corresponding Win32 function. - */ -static inline int -closesocket(SOCKET s) -{ - return close(s); -} - -/** - * Closes socket, substitute for the corresponding Win32 function. - */ -static inline int -ioctlsocket( SOCKET s, long cmd, u_long* argp) -{ - return ioctl(s, cmd, argp); -} - -/** - * Initializes critical-section lock objects. - */ -static inline void -InitializeCriticalSections(jdwpTransportEnv* env) -{ - pthread_mutex_init(&(((internalEnv*)env->functions->reserved1)->readLock), 0); - pthread_mutex_init(&(((internalEnv*)env->functions->reserved1)->sendLock), 0); -} - -/** - * Releases all resources used by critical-section lock objects. - */ -static inline void -DeleteCriticalSections(jdwpTransportEnv* env) -{ - pthread_mutex_destroy(&(((internalEnv*)env->functions->reserved1)->readLock)); - pthread_mutex_destroy(&(((internalEnv*)env->functions->reserved1)->sendLock)); -} - -/** - * Waits for ownership of the read critical-section object. - */ -static inline void -EnterCriticalReadSection(jdwpTransportEnv* env) -{ - pthread_mutex_lock(&(((internalEnv*)env->functions->reserved1)->readLock)); -} - -/** - * Waits for ownership of the send critical-section object. - */ -static inline void -EnterCriticalSendSection(jdwpTransportEnv* env) -{ - pthread_mutex_lock(&(((internalEnv*)env->functions->reserved1)->sendLock)); -} - -/** - * Releases ownership of the read critical-section object. - */ -static inline void -LeaveCriticalReadSection(jdwpTransportEnv* env) -{ - pthread_mutex_unlock(&(((internalEnv*)env->functions->reserved1)->readLock)); -} - -/** - * Releases ownership of the send critical-section object. - */ -static inline void -LeaveCriticalSendSection(jdwpTransportEnv* env) -{ - pthread_mutex_unlock(&(((internalEnv*)env->functions->reserved1)->sendLock)); -} - -static inline ThreadId_t -GetCurrentThreadId() -{ - return pthread_self(); -} // GetCurrentThreadId() - -static inline bool -ThreadId_equal(ThreadId_t treadId1, ThreadId_t treadId2) -{ - return pthread_equal(treadId1, treadId2) != 0 ? true : false; -} // ThreadId_equal() #endif //_SOCKETTRANSPORT_PD_H Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/makefile URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/makefile?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/makefile (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/unix/transport/makefile Wed May 7 04:41:26 2008 @@ -30,7 +30,7 @@ CXXFLAGS += -fpic INCLUDES += -I$(CMNTRANS)common -I$(CMNTRANS)dt_socket \ - -I$(COMMON)generic -Idt_socket + -I$(COMMON)generic -Idt_socket -I$(HY_HDK)/include/port/unix_include LDFLAGS += -lstdc++ @@ -38,7 +38,7 @@ $(CMNTRANS)common/LastTransportError.o \ $(CMNTRANS)dt_socket/SocketTransport.o -MDLLIBFILES = +MDLLIBFILES = $(LIBPATH)libj9vmi.a $(LIBPATH)libj9prt24.so DLLNAME = ../libdt_socket.so Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/core/TransportManager_pd.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/core/TransportManager_pd.cpp?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/core/TransportManager_pd.cpp (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/core/TransportManager_pd.cpp Wed May 7 04:41:26 2008 @@ -99,27 +99,4 @@ CloseHandle(pi.hThread); } -LoadedLibraryHandler TransportManager::LoadTransport(const char* dirName, const char* transportName) -{ - JDWP_TRACE_ENTRY("LoadTransport(" << JDWP_CHECK_NULL(dirName) << ',' << JDWP_CHECK_NULL(transportName) << ')'); - JDWP_ASSERT(transportName != 0); - char* transportFullName = 0; - if (dirName == 0) { - size_t length = strlen(transportName) + 5; - transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); - sprintf(transportFullName, "%s.dll", transportName); - } else { - size_t length = strlen(dirName) + strlen(transportName) + 6; - transportFullName = static_cast(GetMemoryManager().Allocate(length JDWP_FILE_LINE)); - sprintf(transportFullName, "%s\\%s.dll", dirName, transportName); - } - AgentAutoFree afv(transportFullName JDWP_FILE_LINE); - LoadedLibraryHandler res = LoadLibrary(transportFullName); - if (res == 0) { - JDWP_TRACE_PROG("LoadTransport: loading library " << transportFullName << " failed (error code: " << GetLastError() << ")"); - } else { - JDWP_TRACE_PROG("LoadTransport: transport library " << transportFullName << " loaded"); - } - return res; -} Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/makefile URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/makefile?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/makefile (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/agent/makefile Wed May 7 04:41:26 2008 @@ -30,7 +30,7 @@ -I$(CMNAGENT)commands -I$(CMNAGENT)core \ -I$(COMMON)generic -Icore -HYCFLAGS = -I..\..\..\include $(HYCFLAGS) $(INCLUDES) -GX -wd4290 +HYCFLAGS = $(HYCFLAGS) $(INCLUDES) -GX -wd4290 HYLDFLAGS = $(HYLDFLAGS) -def:$(LIBBASE).def @@ -62,7 +62,7 @@ SYSLIBFILES = -MDLLIBFILES = +MDLLIBFILES =$(LIBPATH)vmi.lib $(LIBPATH)j9thr.lib $(LIBPATH)j9prt.lib DLLBASE=0x13200000 COMMENT=/comment:"JDWP agent native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable." Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/dt_socket/SocketTransport_pd.h URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/dt_socket/SocketTransport_pd.h?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/dt_socket/SocketTransport_pd.h (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/dt_socket/SocketTransport_pd.h Wed May 7 04:41:26 2008 @@ -35,16 +35,18 @@ #if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_) #undef _WINSOCKAPI_ #endif +#ifndef HY_NO_THR +#define HY_NO_THR #include #include -typedef CRITICAL_SECTION CriticalSection; -typedef DWORD ThreadId_t; - #include "jdwpTransport.h" +#include "vmi.h" +#include "j9port.h" #include "LastTransportError.h" #include "SocketTransport.h" +#include "jni.h" typedef int socklen_t; @@ -59,66 +61,5 @@ { return WSAGetLastError(); } //GetLastErrorStatus() - -/** - * Initializes critical section lock objects. - */ -static inline void -InitializeCriticalSections(jdwpTransportEnv* env) -{ - InitializeCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock)); - InitializeCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock)); -} //InitializeCriticalSections() - -/** - * Releases all resources used by critical-section lock objects. - */ -static inline void -DeleteCriticalSections(jdwpTransportEnv* env) -{ - DeleteCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock)); - DeleteCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock)); -} //DeleteCriticalSections() - -/** - * Waits for ownership of the read critical-section object. - */ -static inline void -EnterCriticalReadSection(jdwpTransportEnv* env) -{ - EnterCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock)); -} //EnterCriticalReadSection() - -/** - * Waits for ownership of the send critical-section object. - */ -static inline void -EnterCriticalSendSection(jdwpTransportEnv* env) -{ - EnterCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock)); -} //EnterCriticalSendSection() - -/** - * Releases ownership of the read critical-section object. - */ -static inline void -LeaveCriticalReadSection(jdwpTransportEnv* env) -{ - LeaveCriticalSection(&(((internalEnv*)env->functions->reserved1)->readLock)); -} //LeaveCriticalReadSection() - -/** - * Releases ownership of the send critical-section object. - */ -static inline void -LeaveCriticalSendSection(jdwpTransportEnv* env) -{ - LeaveCriticalSection(&(((internalEnv*)env->functions->reserved1)->sendLock)); -} //LeaveCriticalSendSection() - -static inline bool ThreadId_equal(ThreadId_t treadId1, ThreadId_t treadId2) -{ - return (treadId1 == treadId2); -} // ThreadId_equal() - -#endif // _SOCKETTRANSPORT_PD_H +#endif // HY_NO_THR +#endif // _SOCKETTRANSPORT_PD_Hi Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/makefile URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/makefile?rev=654075&r1=654074&r2=654075&view=diff ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/makefile (original) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/windows/transport/makefile Wed May 7 04:41:26 2008 @@ -27,6 +27,7 @@ LIBNAME=$(LIBPATH)$(LIBBASE).lib INCLUDES = $(INCLUDES) \ + -I$(HY_HDK)\include\port\win32_include \ -I$(CMNTRANS)common -I$(CMNTRANS)dt_socket \ -I$(COMMON)generic -Idt_socket @@ -43,7 +44,7 @@ SYSLIBFILES = -MDLLIBFILES = +MDLLIBFILES =$(LIBPATH)vmi.lib $(LIBPATH)j9thr.lib $(LIBPATH)j9prt.lib DLLBASE=0x13200000 COMMENT=/comment:"JDWP socket transport native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."