src/jdk.jpackage/share/native/libapplauncher/JavaVirtualMachine.cpp
author herrick
Fri, 12 Apr 2019 10:54:10 -0400
branchJDK-8200758-branch
changeset 57323 66c1dbc008c5
parent 57316 2891b3ae222d
child 57455 f1290ca0fee6
permissions -rw-r--r--
8217895: jpackage --identifer purpose Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     1
/*
57106
ea870b9ce89a 8216492: Update copyright of all new jpackage fils to 2019
kcr
parents: 57099
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     4
 *
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    10
 *
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    15
 * accompanied this code).
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    16
 *
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    20
 *
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    23
 * questions.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    24
 */
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    25
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    26
#include "JavaVirtualMachine.h"
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    27
#include "Platform.h"
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    28
#include "PlatformString.h"
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    29
#include "FilePath.h"
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    30
#include "Package.h"
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    31
#include "Helpers.h"
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    32
#include "Messages.h"
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    33
#include "Macros.h"
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    34
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    35
#include "jni.h"
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    36
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    37
#include <map>
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    38
#include <list>
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    39
#include <sstream>
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    40
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    41
57099
9a85a7a076ad 8216190: Remove Single Instance Service support from jpackage
herrick
parents: 57064
diff changeset
    42
bool RunVM() {
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    43
    JavaVirtualMachine javavm;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    44
57099
9a85a7a076ad 8216190: Remove Single Instance Service support from jpackage
herrick
parents: 57064
diff changeset
    45
    bool result = javavm.StartJVM();
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    46
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    47
    if (!result) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    48
        Platform& platform = Platform::GetInstance();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    49
        platform.ShowMessage(_T("Failed to launch JVM\n"));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    50
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    51
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    52
    return result;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    53
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    54
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    55
//----------------------------------------------------------------------------
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    56
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    57
JavaOptions::JavaOptions(): FOptions(NULL) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    58
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    59
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    60
JavaOptions::~JavaOptions() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    61
    if (FOptions != NULL) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    62
        for (unsigned int index = 0; index < GetCount(); index++) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    63
            delete[] FOptions[index].optionString;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    64
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    65
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    66
        delete[] FOptions;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    67
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    68
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    69
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    70
void JavaOptions::AppendValue(const TString Key, TString Value, void* Extra) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    71
    JavaOptionItem item;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    72
    item.name = Key;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    73
    item.value = Value;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    74
    item.extraInfo = Extra;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    75
    FItems.push_back(item);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    76
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    77
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    78
void JavaOptions::AppendValue(const TString Key, TString Value) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    79
    AppendValue(Key, Value, NULL);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    80
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    81
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    82
void JavaOptions::AppendValue(const TString Key) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    83
    AppendValue(Key, _T(""), NULL);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    84
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    85
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    86
void JavaOptions::AppendValues(OrderedMap<TString, TString> Values) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    87
    std::vector<TString> orderedKeys = Values.GetKeys();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    88
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    89
    for (std::vector<TString>::const_iterator iterator = orderedKeys.begin();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    90
        iterator != orderedKeys.end(); iterator++) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    91
        TString name = *iterator;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    92
        TString value;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    93
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    94
        if (Values.GetValue(name, value) == true) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    95
            AppendValue(name, value);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    96
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    97
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    98
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
    99
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   100
void JavaOptions::ReplaceValue(const TString Key, TString Value) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   101
    for (std::list<JavaOptionItem>::iterator iterator = FItems.begin();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   102
        iterator != FItems.end(); iterator++) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   103
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   104
        TString lkey = iterator->name;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   105
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   106
        if (lkey == Key) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   107
            JavaOptionItem item = *iterator;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   108
            item.value = Value;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   109
            iterator = FItems.erase(iterator);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   110
            FItems.insert(iterator, item);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   111
            break;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   112
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   113
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   114
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   115
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   116
std::list<TString> JavaOptions::ToList() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   117
    std::list<TString> result;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   118
    Macros& macros = Macros::GetInstance();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   119
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   120
    for (std::list<JavaOptionItem>::const_iterator iterator = FItems.begin();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   121
        iterator != FItems.end(); iterator++) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   122
        TString key = iterator->name;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   123
        TString value = iterator->value;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   124
        TString option = Helpers::NameValueToString(key, value);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   125
        option = macros.ExpandMacros(option);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   126
        result.push_back(option);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   127
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   128
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   129
    return result;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   130
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   131
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   132
size_t JavaOptions::GetCount() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   133
    return FItems.size();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   134
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   135
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   136
//----------------------------------------------------------------------------
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   137
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   138
JavaVirtualMachine::JavaVirtualMachine() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   139
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   140
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   141
JavaVirtualMachine::~JavaVirtualMachine(void) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   142
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   143
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   144
bool JavaVirtualMachine::StartJVM() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   145
    Platform& platform = Platform::GetInstance();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   146
    Package& package = Package::GetInstance();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   147
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   148
    TString classpath = package.GetClassPath();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   149
    TString modulepath = package.GetModulePath();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   150
    JavaOptions options;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   151
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   152
    if (modulepath.empty() == false) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   153
        options.AppendValue(_T("-Djava.module.path"), modulepath);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   154
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   155
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   156
    options.AppendValue(_T("-Djava.library.path"),
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   157
            package.GetPackageAppDirectory() + FilePath::PathSeparator()
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   158
            + package.GetPackageLauncherDirectory());
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   159
    options.AppendValue(
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   160
            _T("-Djava.launcher.path"), package.GetPackageLauncherDirectory());
57316
2891b3ae222d 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57194
diff changeset
   161
    options.AppendValues(package.GetJavaOptions());
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   162
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   163
#ifdef DEBUG
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   164
    if (package.Debugging() == dsJava) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   165
        options.AppendValue(_T("-Xdebug"), _T(""));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   166
        options.AppendValue(
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   167
                _T("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=localhost:5005"),
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   168
                _T(""));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   169
        platform.ShowMessage(_T("localhost:5005"));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   170
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   171
#endif // DEBUG
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   172
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   173
    TString maxHeapSizeOption;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   174
    TString minHeapSizeOption;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   175
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   176
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   177
    if (package.GetMemoryState() == PackageBootFields::msAuto) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   178
        TPlatformNumber memorySize = package.GetMemorySize();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   179
        TString memory =
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   180
                PlatformString((size_t)memorySize).toString() + _T("m");
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   181
        maxHeapSizeOption = TString(_T("-Xmx")) + memory;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   182
        options.AppendValue(maxHeapSizeOption, _T(""));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   183
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   184
        if (memorySize > 256)
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   185
            minHeapSizeOption = _T("-Xms256m");
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   186
        else
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   187
            minHeapSizeOption = _T("-Xms") + memory;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   188
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   189
        options.AppendValue(minHeapSizeOption, _T(""));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   190
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   191
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   192
    TString mainClassName = package.GetMainClassName();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   193
    TString mainModule = package.GetMainModule();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   194
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   195
    if (mainClassName.empty() == true && mainModule.empty() == true) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   196
        Messages& messages = Messages::GetInstance();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   197
        platform.ShowMessage(messages.GetMessage(NO_MAIN_CLASS_SPECIFIED));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   198
        return false;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   199
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   200
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   201
    configureLibrary();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   202
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   203
    // Initialize the arguments to JLI_Launch()
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   204
    //
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   205
    // On Mac OS X JLI_Launch spawns a new thread that actually starts the JVM.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   206
    // This new thread simply re-runs main(argc, argv). Therefore we do not
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   207
    // want to add new args if we are still in the original main thread so we
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   208
    // will treat them as command line args provided by the user ...
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   209
    // Only propagate original set of args first time.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   210
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   211
    options.AppendValue(_T("-classpath"));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   212
    options.AppendValue(classpath);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   213
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   214
    std::list<TString> vmargs;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   215
    vmargs.push_back(package.GetCommandName());
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   216
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   217
    if (package.HasSplashScreen() == true) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   218
        options.AppendValue(TString(_T("-splash:"))
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   219
                + package.GetSplashScreenFileName(), _T(""));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   220
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   221
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   222
    if (mainModule.empty() == true) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   223
        options.AppendValue(Helpers::ConvertJavaPathToId(mainClassName),
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   224
                _T(""));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   225
    } else {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   226
        options.AppendValue(_T("-m"));
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   227
        options.AppendValue(mainModule);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   228
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   229
57099
9a85a7a076ad 8216190: Remove Single Instance Service support from jpackage
herrick
parents: 57064
diff changeset
   230
    return launchVM(options, vmargs);
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   231
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   232
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   233
void JavaVirtualMachine::configureLibrary() {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   234
    Platform& platform = Platform::GetInstance();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   235
    Package& package = Package::GetInstance();
57316
2891b3ae222d 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57194
diff changeset
   236
    TString libName = package.GetJavaLibraryFileName();
57194
9d5fccd97421 8212091: Move jpackage native code under platform specific folders and files
herrick
parents: 57106
diff changeset
   237
    platform.addPlatformDependencies(&javaLibrary);
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   238
    javaLibrary.Load(libName);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   239
}
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   240
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   241
bool JavaVirtualMachine::launchVM(JavaOptions& options,
57099
9a85a7a076ad 8216190: Remove Single Instance Service support from jpackage
herrick
parents: 57064
diff changeset
   242
        std::list<TString>& vmargs) {
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   243
    Platform& platform = Platform::GetInstance();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   244
    Package& package = Package::GetInstance();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   245
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   246
#ifdef MAC
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   247
    // Mac adds a ProcessSerialNumber to args when launched from .app
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   248
    // filter out the psn since they it's not expected in the app
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   249
    if (platform.IsMainThread() == false) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   250
        std::list<TString> loptions = options.ToList();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   251
        vmargs.splice(vmargs.end(), loptions,
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   252
                loptions.begin(), loptions.end());
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   253
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   254
#else
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   255
    std::list<TString> loptions = options.ToList();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   256
    vmargs.splice(vmargs.end(), loptions, loptions.begin(), loptions.end());
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   257
#endif
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   258
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   259
    std::list<TString> largs = package.GetArgs();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   260
    vmargs.splice(vmargs.end(), largs, largs.begin(), largs.end());
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   261
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   262
    size_t argc = vmargs.size();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   263
    DynamicBuffer<char*> argv(argc + 1);
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   264
    if (argv.GetData() == NULL) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   265
        return false;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   266
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   267
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   268
    unsigned int index = 0;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   269
    for (std::list<TString>::const_iterator iterator = vmargs.begin();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   270
        iterator != vmargs.end(); iterator++) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   271
        TString item = *iterator;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   272
        std::string arg = PlatformString(item).toStdString();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   273
#ifdef DEBUG
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   274
        printf("%i %s\n", index, arg.c_str());
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   275
#endif // DEBUG
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   276
        argv[index] = PlatformString::duplicate(arg.c_str());
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   277
        index++;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   278
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   279
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   280
    argv[argc] = NULL;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   281
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   282
// On Mac we can only free the boot fields if the calling thread is
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   283
// not the main thread.
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   284
#ifdef MAC
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   285
    if (platform.IsMainThread() == false) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   286
        package.FreeBootFields();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   287
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   288
#else
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   289
    package.FreeBootFields();
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   290
#endif // MAC
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   291
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   292
    if (javaLibrary.JavaVMCreate(argc, argv.GetData()) == true) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   293
        return true;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   294
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   295
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   296
    for (index = 0; index < argc; index++) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   297
        if (argv[index] != NULL) {
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   298
            delete[] argv[index];
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   299
        }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   300
    }
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   301
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   302
    return false;
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
diff changeset
   303
}