javaruntimes/starterutils/src.linux/jvmstarterjni.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2009 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:  This class is meant for starting the J9 JVM.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef JVMSTARTERJNI_H
       
    20 #define JVMSTARTERJNI_H
       
    21 
       
    22 #include <vector>
       
    23 #include <jni.h>
       
    24 
       
    25 #include "jvmstarterimpl.h"
       
    26 
       
    27 typedef std::vector<JavaVMOption> JvmOptionArgs_t;
       
    28 
       
    29 namespace java // codescanner::namespace
       
    30 {
       
    31 namespace runtime // codescanner::namespace
       
    32 {
       
    33 
       
    34 /**
       
    35  * Provides a utilities for starting the Sun JVM in Linux.
       
    36  */
       
    37 class JvmStarterJni : public JvmStarterImpl
       
    38 {
       
    39 public:
       
    40     /**
       
    41      * Default constructor of the JvmStarterJni.
       
    42      */
       
    43     JvmStarterJni();
       
    44 
       
    45     /**
       
    46      * Constructor of the JvmStarterJni with arguments. For the argument
       
    47      * description @see jvmstarte.h#getJvmStarterInstance method with
       
    48      * same arguments
       
    49      */
       
    50     JvmStarterJni(const Configuration configuration,
       
    51                   const std::wstring& indetifier);
       
    52 
       
    53     /**
       
    54      * Destructor of the JvmStarterJni.
       
    55      */
       
    56     virtual ~JvmStarterJni();
       
    57 
       
    58     /**
       
    59      * @see jvmstarter.h
       
    60      */
       
    61     virtual int startJvm();
       
    62     /**
       
    63      * @see jvmstarter.h
       
    64      */
       
    65     virtual int startJvm(int argc, char** argv);
       
    66 
       
    67     /**
       
    68      * @see jvmstarter.h
       
    69      */
       
    70     virtual void overrideOldHeapSize(int heapSize);
       
    71 
       
    72     /**
       
    73      * @see jvmstarter.h
       
    74      */
       
    75     virtual void overrideNewHeapSize(int heapSize);
       
    76 
       
    77     /**
       
    78      * @see jvmstarter.h
       
    79      */
       
    80     virtual void overrideNativeStackSize(int stackSize);
       
    81 
       
    82     /**
       
    83      * @see jvmstarter.h
       
    84      */
       
    85     virtual void overrideJavaStackSize(int stackSize);
       
    86 
       
    87 private:
       
    88     /**
       
    89      * Sets the default arguments optimized for the MIDP runtime
       
    90      */
       
    91     void setDefaultArguments();
       
    92 
       
    93     /**
       
    94      * Adds the classpaths, main class, JIT configurations and thread
       
    95      * configurations to be part of the internal lists mJvmArgs and
       
    96      * mAppAndArgs.
       
    97      */
       
    98     void completeArgumentContainers();
       
    99 
       
   100     /**
       
   101      * Creates a jobjectArray containing application arguments as
       
   102      * Java Strings.
       
   103      * @param env A pointer to valid JNIEnv.
       
   104      * @return jobjectArray containing application arguments as
       
   105      *         Java Strings.
       
   106      */
       
   107     jobjectArray getApplicationArguments(JNIEnv* env);
       
   108 
       
   109     /**
       
   110      * Starts finally the JVM. This method assumes that all the JVM
       
   111      * arguments are passed as arguments, but the the list must not
       
   112      * contain the main class nor the arguments for the Java application.
       
   113      * The method assumes that these can be found from member variable
       
   114      * mAppAndArgs. This method assumes that arguments for the JVM will
       
   115      * be set to memeber variables mArgCount and mArgs. The method should
       
   116      * not be run in the primordial thread.
       
   117      * @return status, 0 in success case.
       
   118      */
       
   119     int startJvmImpl();
       
   120 
       
   121     /**
       
   122      * Creates a new thread for starting the JVM.
       
   123      * @argc Number of JVM arguments.
       
   124      * @argv JVM arguments in UTF-8 format.
       
   125      * @return status, 0 in success case.
       
   126      */
       
   127     int startJvmInSeparateThread(int argc, char** argv);
       
   128 
       
   129 
       
   130 
       
   131     /**
       
   132      * Sun's JVM requires that the JVM is started in non-primordial thread
       
   133      * (http://blogs.sun.com/ksrini/entry/hotspot_primordial_thread_jni_stack).
       
   134      * This is an entry point of the new thread where the JVM is started.
       
   135      * @param arg A pointer instance of this class.
       
   136      * @return status of the call.
       
   137      */
       
   138     static void* javaThreadMain(void* arg);
       
   139 
       
   140 private:
       
   141 
       
   142     /** Number of JVM arguments. */
       
   143     int          mArgCount;
       
   144 
       
   145     /** JVM arguments in UTF-8 format. Not owned. */
       
   146     char**       mArgs;
       
   147 };
       
   148 } // end namespace runtime
       
   149 } // end namespace java
       
   150 
       
   151 #endif // JVMSTARTERJNI_H
       
   152