The port library is implemented as a table of function pointers. One advantage of a function pointer based table is the ability to replace any functionality without recompiling the entire Java virtual machine. For example if an application is experiencing a memory leak, the memory management functions of the port library can be replaced to help determine the root cause of this leak. Alternatively applications wishing to control all memory allocation can provide their own routines to override the platform specific allocation and deallocation of memory.
Various implementations of the port library may choose not to implement all functionality contained in the port library table. If a platform does not support sockets, and thus the Java virtual machine does not utilize sockets, the port library does not need to provide a valid socket behavior. The port library contains version control information that enables applications to determine if required functionality is supported. In addition the version control information allows applications to determine if the port library provided is compatible with the one which they were compiled against.
Applications may use the port library with no modifications as follows. In this example a port library is declared on the stack. Of course, the stack allocated data must remain valid for the duration of the port library usage. All utility functions and data structures related to the port library are defined in the header file hyport.h.
{ int rc; HyPortLibrary hyportLibrary; HyPortLibraryVersion portLibraryVersion; // Use portlibrary version which we compiled against, and have allocated space // for on the stack. This version may be different from the one in the linked DLL. HYPORT_SET_VERSION(&portLibraryVersion, HYPORT_CAPABILITY_MASK); // Initialize and start the port library rc = hyport_init_library(&hyportLibrary, &portLibraryVersion, sizeof(HyPortLibrary)); if (0 != rc) { // handle error condition } ... }
Applications wishing to override port library functionality can do so by first allocating the port library table, then initializing it with the default values. They can then override specific function pointers as required and then finally start the port library.
{ int rc; HyPortLibrary hyportLibrary; HyPortLibraryVersion portLibraryVersion; // Use portlibrary version which we compiled against, and have allocated space // for on the stack. This version may be different from the one in the linked DLL. HYPORT_SET_VERSION(&portLibraryVersion, HYPORT_CAPABILITY_MASK); // Initializes the port library with the default functions for the specified version rc = hyport_create_library(hyportLibrary, &portLibraryVersion, sizeof(HyPortLibrary)); if (0 != rc) { // handle error condition } // override the file_write operation, store the old one so we can restore it later old_write = hyportLibrary->file_write; hyportLibrary->file_write = dbg_write; // Now start the port library rc = hyport_startup_library(hyportLibrary); if (0 != rc) { // handle error condition } }
If the application wishes to dynamically allocate memory for the port library they need to first determine the size required.
{ int rc; int hyportLibrarySize; HyPortLibrary* hyportLibrary; HyPortLibraryVersion portLibraryVersion; // Use portlibrary version which we compiled against, and have allocated space // for on the stack. This version may be different from the one in the linked DLL. HYPORT_SET_VERSION(&portLibraryVersion, HYPORT_CAPABILITY_MASK); // Allocate space for the port library hyportLibrarySize = (int) hyport_getsize(&portLibraryVersion); if (0 == hyportLibrarySize) { // handle error condition } hyportLibrary = (HyPortLibrary*)malloc(hyportLibrarySize); if (NULL == hyportLibrary) { // handle error condition } // Initialize and start the port library rc = hyport_init_library(hyportLibrary, &portLibraryVersion, hyportLibrarySize); if (0 != rc) { // handle error condition } ... }
void *internalAllocateMemory(JNIEnv *jniEnv) { PORT_ACCESS_FROM_ENV(jniEnv); return hymem_allocate_memory(1024); } void *internalAllocateMemory(HyPortLibrary *portLibrary) { return portLibrary->mem_allocate_memory(portLibrary, 1024); }
Files | |
file | hycpu.c |
CPU Control. | |
file | hyfile.c |
file | |
file | hyfiletext.c |
file | |
file | hyipcmutex.c |
Shared Resource Mutex. | |
file | hymem.c |
Memory Utilities. | |
file | hymmap.c |
Memory map. | |
file | hyosdump.c |
Dump formatting. | |
file | hyportptb.h |
Per Thread Buffers. | |
file | hyshmem.c |
Shared Memory Semaphores. | |
file | hyshsem.c |
Shared Semaphores. | |
file | hysl.c |
shared library | |
file | hysock.c |
Sockets. | |
file | hysysinfo.c |
System information. | |
file | hytime.c |
Timer utilities. | |
file | hytty.c |
TTY output. | |
file | hyvmem.c |
Virtual memory. | |
file | hyerror.c |
Error Handling. | |
file | hyexit.c |
Process shutdown. | |
file | hygp.c |
Provides platform-neutral signal handling functions. | |
file | hynls.c |
Native language support. | |
file | hyport.c |
Port Library. | |
file | hystr.c |
String utilities. | |
file | hystrftime.c |
Time formatting utilities. | |
file | hystsl.c |
Static shared library. | |
file | hytlshelpers.c |
Per Thread Buffer Support. | |
file | hyport.h |
Port Library Header. | |
file | hyporterror.h |
Port Library Error Codes. |
Genereated on Tue Dec 9 14:13:00 2008 by Doxygen.
(c) Copyright 2005, 2008 The Apache Software Foundation or its licensors, as applicable.