javacommons/utils/javasrc/com/nokia/mj/impl/rt/j9/JvmPortCommon.java
changeset 21 2a9601315dfc
child 80 d6dafc5d983f
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.j9;
       
    19 
       
    20 import com.ibm.oti.vm.VM;
       
    21 import com.nokia.mj.impl.rt.JvmPort;
       
    22 import com.nokia.mj.impl.rt.support.ThreadEventListener;
       
    23 import com.nokia.mj.impl.rt.support.NativeMemoryBlock;
       
    24 
       
    25 /**
       
    26  *
       
    27  * @author Nokia Corporation
       
    28  * @version 1.0
       
    29  */
       
    30 
       
    31 abstract class JvmPortCommon extends JvmPort
       
    32 {
       
    33 
       
    34     ThreadEventListener                     mClientListener = null;
       
    35     com.ibm.oti.util.ThreadEventListener    mVmListener = null;
       
    36     /**
       
    37      * @see com.nokia.mj.impl.runtimesupport.JvmPort#runYoungGenerationGc.
       
    38      */
       
    39     public final boolean runYoungGenerationGc()
       
    40     {
       
    41         VM.localGC();
       
    42         return true;
       
    43     }
       
    44 
       
    45 
       
    46     /**
       
    47      * @see com.nokia.mj.impl.runtimesupport.JvmPort#getResourceAsNativeMemory.
       
    48      */
       
    49     public final NativeMemoryBlock getResourceAsNativeMemory(String jarPath, String resName)
       
    50     {
       
    51         return new NativeMemoryBlockImpl(jarPath, resName);
       
    52     }
       
    53 
       
    54     /**
       
    55      * @see com.nokia.mj.impl.runtimesupport.JvmPort#disableRuntimeExit.
       
    56      */
       
    57     public final void disableRuntimeExit()
       
    58     {
       
    59         VM.stopExit();
       
    60     }
       
    61 
       
    62     /**
       
    63      * @see com.nokia.mj.impl.runtimesupport.JvmPort#enableRuntimeExit.
       
    64      */
       
    65     public final void enableRuntimeExit()
       
    66     {
       
    67         VM.allowMidpExit();
       
    68     }
       
    69 
       
    70     /**
       
    71      * @see com.nokia.mj.impl.runtimesupport.JvmPort#exitVm.
       
    72      */
       
    73     public final void exitVm(int status)
       
    74     {
       
    75         System.exit(status);
       
    76     }
       
    77 
       
    78     /**
       
    79      * @see com.nokia.mj.impl.runtimesupport.JvmPort#setThreadEventListener.
       
    80      */
       
    81     public void setThreadEventListener(ThreadEventListener listener)
       
    82     {
       
    83         mClientListener = listener;
       
    84         if (mVmListener == null)
       
    85         {
       
    86             mVmListener = new com.ibm.oti.util.ThreadEventListener()
       
    87             {
       
    88                 public void threadStarting(Thread newThread, Thread parentThread)
       
    89                 {
       
    90                     mClientListener.threadStarting(newThread, parentThread);
       
    91                 }
       
    92 
       
    93                 public void threadDeath(Thread thread)
       
    94                 {
       
    95                     mClientListener.threadDied(thread);
       
    96                 }
       
    97 
       
    98                 public void uncaughtException(Thread thread, Throwable throwable)
       
    99                 {
       
   100                     mClientListener.uncaughtException(thread, throwable);
       
   101                 }
       
   102             };
       
   103             com.ibm.oti.util.ThreadEventHook.setListener(mVmListener);
       
   104         }
       
   105     }
       
   106 
       
   107     /**
       
   108      * @see com.nokia.mj.impl.runtimesupport.JvmPort#addRestrictedPackagePrefixes.
       
   109      */
       
   110     public final void addRestrictedPackagePrefixes(String[] packageNames)
       
   111     throws SecurityException
       
   112     {
       
   113         VM.addRestrictedPackages(packageNames);
       
   114     }
       
   115 
       
   116     /**
       
   117      * @see com.nokia.mj.impl.runtimesupport.JvmPort#addProtectedPackagePrefixes.
       
   118      */
       
   119     public final void addProtectedPackagePrefixes(String[] packageNames)
       
   120     throws SecurityException
       
   121     {
       
   122         VM.addProtectedPackages(packageNames);
       
   123     }
       
   124 
       
   125     /**
       
   126      * @see com.nokia.mj.impl.runtimesupport.JvmPort#appendClasspath.
       
   127      */
       
   128     public final void appendToClassPath(String path)
       
   129     {
       
   130         VM.appendToClassPath(path);
       
   131     }
       
   132 
       
   133     /**
       
   134      * @see com.nokia.mj.impl.runtimesupport.JvmPort#shrinkJavaHeapToMinimum.
       
   135      */
       
   136     public final int shrinkJavaHeapToMinimum()
       
   137     {
       
   138         return VM.contractOldSpaceFully();
       
   139     }
       
   140 
       
   141     /**
       
   142      * @see com.nokia.mj.impl.runtimesupport.JvmPort#expandJavaHeap.
       
   143      */
       
   144     public final int expandJavaHeap(int amount)
       
   145     {
       
   146         return VM.expandOldSpace(amount);
       
   147     }
       
   148 
       
   149 }