You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/26 09:07:02 UTC

svn commit: r1096678 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform: unix/ExecutableMemoryPointer.java windows/ExecutableMemoryPointer.java

Author: mturk
Date: Tue Apr 26 07:07:02 2011
New Revision: 1096678

URL: http://svn.apache.org/viewvc?rev=1096678&view=rev
Log:
Add execmem stubs

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/ExecutableMemoryPointer.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ExecutableMemoryPointer.java   (with props)

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/ExecutableMemoryPointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/ExecutableMemoryPointer.java?rev=1096678&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/ExecutableMemoryPointer.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/ExecutableMemoryPointer.java Tue Apr 26 07:07:02 2011
@@ -0,0 +1,85 @@
+/* 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.
+ */
+
+package org.apache.commons.runtime.platform.unix;
+
+import org.apache.commons.runtime.Pointer;
+import org.apache.commons.runtime.Status;
+import org.apache.commons.runtime.SystemException;
+
+/**
+ * Represents the Operating System C/C++ executable memory pointer.
+ *
+ * @since Runtime 1.0
+ */
+final class ExecutableMemoryPointer extends Pointer
+{
+
+    private ExecutableMemoryPointer()
+    {
+        // No instance
+    }
+
+    /*
+     * Only created from JNI code.
+     */
+    private ExecutableMemoryPointer(long ptr, long len)
+    {
+        POINTER = ptr;
+        PLENGTH = len;
+    }
+
+    @Override
+    public final boolean isConst()
+    {
+        return false;
+    }
+
+    @Override
+    public final void free()
+        throws Throwable
+    {
+        if (POINTER == 0L)
+            throw new NullPointerException();
+        try {
+            int rc = Posix.munmap(POINTER, PLENGTH);
+            if (rc != 0) {
+                throw new SystemException(Status.describe(rc));
+            }
+        } finally {
+            POINTER = 0L;
+        }
+    }
+
+    /**
+     * Called by the garbage collector when the object is destroyed.
+     * The class will free internal resources allocated by the Operating system.
+     * @see Object#finalize()
+     * @throws Throwable the {@code Exception} raised by this method.
+     */
+    @Override
+    protected final void finalize()
+        throws Throwable
+    {
+        try {
+            Posix.munmap(POINTER, PLENGTH);
+        } finally {
+            POINTER = 0L;
+        }
+    }
+    
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/ExecutableMemoryPointer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ExecutableMemoryPointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ExecutableMemoryPointer.java?rev=1096678&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ExecutableMemoryPointer.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ExecutableMemoryPointer.java Tue Apr 26 07:07:02 2011
@@ -0,0 +1,85 @@
+/* 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.
+ */
+
+package org.apache.commons.runtime.platform.windows;
+
+import org.apache.commons.runtime.Pointer;
+import org.apache.commons.runtime.Status;
+import org.apache.commons.runtime.SystemException;
+
+/**
+ * Represents the Operating System C/C++ executable memory pointer.
+ *
+ * @since Runtime 1.0
+ */
+final class ExecutableMemoryPointer extends Pointer
+{
+
+    private ExecutableMemoryPointer()
+    {
+        // No instance
+    }
+
+    /*
+     * Only created from JNI code.
+     */
+    private ExecutableMemoryPointer(long ptr, long len)
+    {
+        POINTER = ptr;
+        PLENGTH = len;
+    }
+
+    @Override
+    public final boolean isConst()
+    {
+        return false;
+    }
+
+    @Override
+    public final void free()
+        throws Throwable
+    {
+        if (POINTER == 0L)
+            throw new NullPointerException();
+        try {
+            int rc = Win32.VirtualFree(POINTER, PLENGTH, Win32.MEM_RELEASE);
+            if (rc != 0) {
+                throw new SystemException(Status.describe(rc));
+            }
+        } finally {
+            POINTER = 0L;
+        }
+    }
+
+    /**
+     * Called by the garbage collector when the object is destroyed.
+     * The class will free internal resources allocated by the Operating system.
+     * @see Object#finalize()
+     * @throws Throwable the {@code Exception} raised by this method.
+     */
+    @Override
+    protected final void finalize()
+        throws Throwable
+    {
+        try {
+            Win32.VirtualFree(POINTER, PLENGTH, Win32.MEM_RELEASE);
+        } finally {
+            POINTER = 0L;
+        }
+    }
+    
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ExecutableMemoryPointer.java
------------------------------------------------------------------------------
    svn:eol-style = native