javacommons/utils/javasrc/com/nokia/mj/impl/rt/JvmPort.java
changeset 21 2a9601315dfc
child 25 9ac0a0a7da70
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 package com.nokia.mj.impl.rt;
       
    19 
       
    20 import java.util.Hashtable;
       
    21 import com.nokia.mj.impl.rt.support.NativeMemoryBlock;
       
    22 import com.nokia.mj.impl.rt.support.ThreadEventListener;
       
    23 import com.nokia.mj.impl.utils.Logger;
       
    24 
       
    25 /**
       
    26  *
       
    27  * @author Nokia Corporation
       
    28  * @version 1.0
       
    29  */
       
    30 
       
    31 public abstract class JvmPort
       
    32 {
       
    33 
       
    34     /**
       
    35      * Property name of VM port
       
    36      */
       
    37     private static final String PORTCLASS_PROPERTY_NAME = "com.nokia.jvm.port";
       
    38 
       
    39     private static final String PORTCLASS_PACKAGE = "com.nokia.mj.impl.rt.";
       
    40 
       
    41     /**
       
    42      * When the class is loaded it will try to create the VM porting class
       
    43      * defined in the system property PORTCLASS_PROPERTY_NAME
       
    44      */
       
    45     private static JvmPort sInstance = null;
       
    46 
       
    47     /**
       
    48      * A reference to object containing properties. In CLDC it is Hashtable,
       
    49      * otherwise it is Properties.
       
    50      */
       
    51     private static Hashtable mPropertiesContainer;
       
    52 
       
    53     protected JvmPort()
       
    54     {
       
    55     }
       
    56 
       
    57     /**
       
    58      * Static initializer
       
    59      */
       
    60     static
       
    61     {
       
    62         String vmPortClass = System.getProperty(PORTCLASS_PROPERTY_NAME);
       
    63         if (vmPortClass == null)
       
    64         {
       
    65             throw new RuntimeException("Not able to load VM port class since "
       
    66                                        + PORTCLASS_PROPERTY_NAME +
       
    67                                        " is undefined");
       
    68         }
       
    69         vmPortClass = PORTCLASS_PACKAGE + vmPortClass;
       
    70         try
       
    71         {
       
    72             Class clazz = Class.forName(vmPortClass);
       
    73             sInstance = (JvmPort)clazz.newInstance();
       
    74         }
       
    75         catch (Exception e)
       
    76         {
       
    77             String errTxt = "Not able to instantiate class " +
       
    78                             vmPortClass + ".";
       
    79             Logger.ELOG(Logger.EUtils, errTxt, e);
       
    80             throw new RuntimeException(errTxt);
       
    81         }
       
    82     }
       
    83 
       
    84     /**
       
    85      * Returns an instcance of class implementing interface JvmPort.
       
    86      *
       
    87      * @return JvmPort
       
    88      */
       
    89     public static JvmPort getInstance()
       
    90     {
       
    91         return sInstance;
       
    92     }
       
    93 
       
    94     /**
       
    95      * Sets the container containing system properties.
       
    96      * @param propertiesContainer system properties.
       
    97      */
       
    98     public static void setPropertiesContainer(Hashtable propertiesContainer)
       
    99     {
       
   100         mPropertiesContainer = propertiesContainer;
       
   101     }
       
   102 
       
   103 
       
   104     /**
       
   105      * @see com.nokia.mj.impl.rt.support.Jvm#loadSystemLibrary(java.lang.String).
       
   106      */
       
   107     public abstract void loadSystemLibrary(String libName);
       
   108 
       
   109     /**
       
   110      * @see com.nokia.mj.impl.rt.support.Jvm#
       
   111      *      loadApplicationClass(java.lang.String).
       
   112      */
       
   113     public abstract Class loadApplicationClass(String name)
       
   114     throws ClassNotFoundException;
       
   115 
       
   116     /**
       
   117      * @see com.nokia.mj.impl.rt.support.JvmInternal#runYoungGenerationGc().
       
   118      */
       
   119     public abstract boolean runYoungGenerationGc();
       
   120 
       
   121     /**
       
   122      * @see com.nokia.mj.impl.rt.support.Jvm#
       
   123      * setThreadAsDaemon((java.lang.Thread, boolean)).
       
   124      */
       
   125     public abstract void setThreadAsDaemon(Thread Thread,
       
   126                                            boolean daemon)
       
   127     throws IllegalThreadStateException,
       
   128                 SecurityException;
       
   129 
       
   130 
       
   131     /**
       
   132      * @see com.nokia.mj.impl.rt.support.Jvm#
       
   133      *      getResourceAsNativeMemory(java.lang.String, java.lang.String).
       
   134      */
       
   135     public abstract
       
   136     NativeMemoryBlock getResourceAsNativeMemory(String jarPath,
       
   137             String resName);
       
   138 
       
   139 
       
   140     /**
       
   141      * @see com.nokia.mj.impl.rt.support.JvmInternal#disableRuntimeExit().
       
   142      */
       
   143     public abstract void disableRuntimeExit();
       
   144 
       
   145     /**
       
   146      * @see com.nokia.mj.impl.rt.support.JvmInternal#enableRuntimeExit().
       
   147      */
       
   148     public abstract void enableRuntimeExit();
       
   149 
       
   150     /**
       
   151      * @see com.nokia.mj.impl.rt.support.JvmInternal#exitVm(int).
       
   152      */
       
   153     public abstract void exitVm(int status);
       
   154 
       
   155     /**
       
   156      * @see com.nokia.mj.impl.rt.support.JvmInternal#
       
   157      * runFinalization().
       
   158      */
       
   159     public abstract void runFinalization();
       
   160 
       
   161     /**
       
   162      * @see com.nokia.mj.impl.rt.support.JvmInternal#
       
   163      * enableFinalization(java.lang.Class).
       
   164      */
       
   165     public abstract void enableFinalization(Class clazz);
       
   166 
       
   167     /**
       
   168      * @see com.nokia.mj.impl.rt.support.JvmInternal#setThreadEventListener
       
   169      * (com.nokia.mj.impl.rt.support.ThreadEventListener).
       
   170      */
       
   171     public abstract void setThreadEventListener(ThreadEventListener listener);
       
   172 
       
   173     /**
       
   174      * @see com.nokia.mj.impl.rt.support.JvmInternal#
       
   175      * addRestrictedPackagePrefixes(java.lang.String[]).
       
   176      */
       
   177     public abstract void addRestrictedPackagePrefixes(String[] packageNames)
       
   178     throws SecurityException;
       
   179 
       
   180     /**
       
   181      * @see com.nokia.mj.impl.rt.support.JvmInternal#
       
   182      * addRestrictedPackagePrefixes(java.lang.String[]).
       
   183      */
       
   184     public abstract void addProtectedPackagePrefixes(String[] packageNames)
       
   185     throws SecurityException;
       
   186 
       
   187 
       
   188     /**
       
   189      * @see com.nokia.mj.impl.runtimesupport.JvmPort#appendClasspath.
       
   190      */
       
   191     public abstract void appendToClassPath(String path);
       
   192 
       
   193     /**
       
   194      * @see com.nokia.mj.impl.runtimesupport.JvmPort#setSystemProperty.
       
   195      */
       
   196     public void setSystemProperty(Object key, Object value)
       
   197 {
       
   198         mPropertiesContainer.put(key, value);
       
   199     }
       
   200 
       
   201     /**
       
   202      * @see com.nokia.mj.impl.runtimesupport.JvmPort#shrinkJavaHeapToMinimum.
       
   203      */
       
   204     public abstract int shrinkJavaHeapToMinimum();
       
   205 
       
   206     /**
       
   207      * @see com.nokia.mj.impl.runtimesupport.JvmPort#expandJavaHeap.
       
   208      */
       
   209     public abstract int expandJavaHeap(int amount);
       
   210 
       
   211 }