8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux
Java Native Compilation
When Java is loaded into the server it is compiled to byte code before execution. The process of native compilation converts Java stored procedures to native code shared libraries which are linked into the kernel resulting in performance increases for the procedural code. The extent of the performance increase depends on the content of the Java. The compilation process does not affect the speed of database calls, only the procedural logic around them such as loops and calculations.
Before we start we must load some Java into our schema (DEV). This article assumes the code from the UUID article is present in the schema. In addition we must load the NativeDemo.java class.
loadjava -schema DEV -user sys/password@tsh -verbose NativeDemo.java
We then publish a call specification using the following code.
CREATE OR REPLACE PROCEDURE NATIVE_DEMO AS LANGUAGE JAVA NAME 'NativeDemo.go()'; /
Running the Java from the database results in the following timing.
SQL> exec native_demo PL/SQL procedure successfully completed. Elapsed: 00:00:02.03
The first step in natively compiling the Java is to grant the following roles to the user.
GRANT JAVA_DEPLOY TO DEV; GRANT JAVASYSPRIV TO DEV;
Next we must prepare the command line environment.
# UNIX JAVA_HOME=/usr/opt/java131; export JAVA_HOME CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar; export CLASSPATH PATH=$JAVA_HOME/bin:$PATH; export PATH LD_LIBRARY_PATH=$JAVA_HOME/lib; export LD_LIBRARY_PATH Rem Windows set JAVA_HOME=C:\Java\jdk1.3.1 set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar set PATH=%JAVA_HOME%\bin;%PATH% set LD_LIBRARY_PATH=%JAVA_HOME%\lib
Next we create a working directory containing a file called NativeDemo.classes with the following contents.
import com.sun.xml.registry.ebxml.util.UUID; import com.sun.xml.registry.ebxml.util.UUIDFactory; import UUIDGenerate; import NativeDemo;
Lots of files are generated during the compilation process so it's important to initiate the process from the working directory. The compilation process is started as following.
% ncomp -user dev/dev@tsh NativeDemo.classes # # this list is produced by query # select status, class_name from jaccelerator$status; # NEED_NCOMPING com/sun/xml/registry/ebxml/util/UUID NEED_NCOMPING com/sun/xml/registry/ebxml/util/UUIDFactory NEED_NCOMPING UUIDGenerate NEED_NCOMPING NativeDemo NEED_NCOMPING com/sun/xml/registry/ebxml/util/ # Deployment History, produced by query: # select timestamp, status, dll_name from jaccelerator$dlls order by dll_name Thu Jun 19 07:53:04 BST 2003 installed /libjox9_f5ded5f298_dev_UnnamedPackage.so Thu Jun 19 07:53:04 BST 2003 installed /libjox9_f5ded5f298_dev_com_sun_xml_registry_ebxml_util.so Thu Jun 19 08:50:26 BST 2003 installed /libjox9_f5df0aac0c_dev_UnnamedPackage.so %
The resulting files are located in the "$ORACLE_HOME/javavm/admin" directory.
When we run the natively compiled Java we can see the performance improvement.
SQL> exec native_demo PL/SQL procedure successfully completed. Elapsed: 00:00:01.00
For more information see:
Hope this helps. Regards Tim...