javaruntimes/starterutils/src/jvmstarterimpl.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     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 JVM.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <string>
       
    20 
       
    21 #include "jvmstarterimpl.h"
       
    22 
       
    23 #include "logger.h"
       
    24 #include "exception"
       
    25 #include "runtimeexception.h"
       
    26 #include "javaoslayer.h"
       
    27 
       
    28 using namespace java::runtime;
       
    29 using namespace java::util;
       
    30 
       
    31 // Platform dependents
       
    32 extern const wchar_t CLASS_PATH_SEPARATOR;
       
    33 extern const char PATH_SEPARATOR_FROM;
       
    34 extern const char PATH_SEPARATOR_TO;
       
    35 
       
    36 JvmStarterImpl::JvmStarterImpl(): mJitDisabled(false),
       
    37         mTheadDumpEnabled(false)
       
    38 {
       
    39     JELOG2(EJavaRuntime);
       
    40 
       
    41     DriveId driveId = JavaOsLayer::getMidpDrive();
       
    42 
       
    43     // Define JAVA_BIN_ROOT system property
       
    44     std::wstring javaBinRoot(L"-DJAVA_BIN_ROOT=");
       
    45     std::string binRoot(driveId.getDriveLetter());
       
    46     JavaOsLayer::getBinRoot(binRoot, true);
       
    47     javaBinRoot.append(binRoot.begin(), binRoot.end());
       
    48     mJvmArgs.push_front(javaBinRoot);
       
    49 
       
    50     // Define JAVA_RES_ROOT system property
       
    51     std::wstring javaResRoot(L"-DJAVA_RES_ROOT=");
       
    52     std::string resourceRoot(driveId.getDriveLetter());
       
    53     JavaOsLayer::getResRoot(resourceRoot, true);
       
    54     javaResRoot.append(resourceRoot.begin(), resourceRoot.end());
       
    55     mJvmArgs.push_front(javaResRoot);
       
    56 }
       
    57 
       
    58 JvmStarterImpl::~JvmStarterImpl()
       
    59 {
       
    60     JELOG2(EJavaRuntime);
       
    61 }
       
    62 
       
    63 void JvmStarterImpl::appendClassPath(const std::wstring& file)
       
    64 {
       
    65     JELOG2(EJavaRuntime);
       
    66     appendAndConvertClassPath(file, mClassPath);
       
    67 }
       
    68 
       
    69 void JvmStarterImpl::appendBootClassPath(const std::wstring& file)
       
    70 {
       
    71     JELOG2(EJavaRuntime);
       
    72     appendAndConvertClassPath(file, mBootClassPathAppend);
       
    73 }
       
    74 
       
    75 void JvmStarterImpl::prependBootClassPath(const std::wstring& file)
       
    76 {
       
    77     JELOG2(EJavaRuntime);
       
    78     appendAndConvertClassPath(file, mBootClassPathPrepend);
       
    79 }
       
    80 
       
    81 void JvmStarterImpl::appendExtensionPath(const std::wstring& extensionPath)
       
    82 {
       
    83     JELOG2(EJavaRuntime);
       
    84     appendAndConvertClassPath(extensionPath, mExtensionPath);
       
    85 }
       
    86 
       
    87 void JvmStarterImpl::setMainClass(const std::wstring& mainClass)
       
    88 {
       
    89     JELOG2(EJavaRuntime);
       
    90     mMainClass = mainClass;
       
    91 }
       
    92 
       
    93 void JvmStarterImpl::appendApplicationArgument(const std::wstring& argument)
       
    94 {
       
    95     JELOG2(EJavaRuntime);
       
    96     mAppAndArgs.push_back(argument);
       
    97 }
       
    98 
       
    99 void JvmStarterImpl::appendSystemProperty(const std::wstring& systemproperty)
       
   100 {
       
   101     JELOG2(EJavaRuntime);
       
   102     mJvmArgs.push_back(systemproperty);
       
   103 }
       
   104 
       
   105 void JvmStarterImpl::appendRawJvmArgument(const std::wstring& argument)
       
   106 {
       
   107     JELOG2(EJavaRuntime);
       
   108     mJvmArgs.push_back(argument);
       
   109 }
       
   110 
       
   111 void JvmStarterImpl::disableJit()
       
   112 {
       
   113     JELOG2(EJavaRuntime);
       
   114     mJitDisabled = true;
       
   115 }
       
   116 
       
   117 void JvmStarterImpl::enableThreadDumping()
       
   118 {
       
   119     JELOG2(EJavaRuntime);
       
   120     mTheadDumpEnabled = true;
       
   121 }
       
   122 
       
   123 void JvmStarterImpl::appendAndConvertClassPath(const std::wstring& source,
       
   124         std::wstring& destination)
       
   125 {
       
   126     JELOG2(EJavaRuntime);
       
   127     if (destination.length() > 0)
       
   128     {
       
   129         // Appending
       
   130         destination += CLASS_PATH_SEPARATOR;
       
   131     }
       
   132     destination += source;
       
   133     std::replace(destination.begin(), destination.end(),
       
   134                  PATH_SEPARATOR_FROM, PATH_SEPARATOR_TO);
       
   135 }
       
   136 
       
   137 void JvmStarterImpl::clear()
       
   138 {
       
   139     JELOG2(EJavaRuntime);
       
   140     mIdentifier.clear();
       
   141     mClassPath.clear();
       
   142     mBootClassPathAppend.clear();
       
   143     mBootClassPathPrepend.clear();
       
   144     mExtensionPath.clear();
       
   145     mMainClass.clear();
       
   146     mJvmArgs.clear();
       
   147     mAppAndArgs.clear();
       
   148 }
       
   149