< prev index next >

src/jdk.jpackage/share/native/libapplauncher/JavaVirtualMachine.cpp

Print this page




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "JavaVirtualMachine.h"
  27 #include "Platform.h"
  28 #include "PlatformString.h"
  29 #include "FilePath.h"
  30 #include "Package.h"
  31 #include "JavaTypes.h"
  32 #include "Helpers.h"
  33 #include "Messages.h"
  34 #include "Macros.h"
  35 #include "PlatformThread.h"
  36 
  37 #include "jni.h"
  38 
  39 #include <map>
  40 #include <list>
  41 #include <sstream>
  42 
  43 
  44 bool RunVM() {
  45     JavaVirtualMachine javavm;
  46 
  47     bool result = javavm.StartJVM();
  48 
  49     if (!result) {
  50         Platform& platform = Platform::GetInstance();
  51         platform.ShowMessage(_T("Failed to launch JVM\n"));
  52     }
  53 
  54     return result;
  55 }
  56 
  57 JavaLibrary::JavaLibrary() : Library(), FCreateProc(NULL)  {
  58 }
  59 
  60 bool JavaLibrary::JavaVMCreate(size_t argc, char *argv[]) {
  61     if (FCreateProc == NULL) {
  62         FCreateProc = (JVM_CREATE)GetProcAddress(LAUNCH_FUNC);
  63     }
  64 
  65     if (FCreateProc == NULL) {
  66         Platform& platform = Platform::GetInstance();
  67         Messages& messages = Messages::GetInstance();
  68         platform.ShowMessage(
  69                 messages.GetMessage(FAILED_LOCATING_JVM_ENTRY_POINT));
  70         return false;
  71     }
  72 
  73     return FCreateProc((int)argc, argv,
  74             0, NULL,
  75             0, NULL,
  76             "",
  77             "",
  78             "java",
  79             "java",
  80             false,
  81             false,
  82             false,
  83             0) == 0;
  84 }
  85 
  86 //----------------------------------------------------------------------------
  87 
  88 JavaOptions::JavaOptions(): FOptions(NULL) {
  89 }
  90 
  91 JavaOptions::~JavaOptions() {
  92     if (FOptions != NULL) {
  93         for (unsigned int index = 0; index < GetCount(); index++) {
  94             delete[] FOptions[index].optionString;
  95         }
  96 
  97         delete[] FOptions;
  98     }
  99 }
 100 
 101 void JavaOptions::AppendValue(const TString Key, TString Value, void* Extra) {
 102     JavaOptionItem item;
 103     item.name = Key;
 104     item.value = Value;
 105     item.extraInfo = Extra;


 248 
 249     if (package.HasSplashScreen() == true) {
 250         options.AppendValue(TString(_T("-splash:"))
 251                 + package.GetSplashScreenFileName(), _T(""));
 252     }
 253 
 254     if (mainModule.empty() == true) {
 255         options.AppendValue(Helpers::ConvertJavaPathToId(mainClassName),
 256                 _T(""));
 257     } else {
 258         options.AppendValue(_T("-m"));
 259         options.AppendValue(mainModule);
 260     }
 261 
 262     return launchVM(options, vmargs);
 263 }
 264 
 265 void JavaVirtualMachine::configureLibrary() {
 266     Platform& platform = Platform::GetInstance();
 267     Package& package = Package::GetInstance();
 268     // TODO: Clean this up. Because of bug JDK-8131321 the opening of the
 269     // PE file ails in WindowsPlatform.cpp on the check to
 270     // if (pNTHeader->Signature == IMAGE_NT_SIGNATURE)
 271     TString libName = package.GetJVMLibraryFileName();
 272 #ifdef _WIN64
 273     if (FilePath::FileExists(_T("msvcr100.dll")) == true) {
 274         javaLibrary.AddDependency(_T("msvcr100.dll"));
 275     }
 276 
 277     TString runtimeBin = platform.GetPackageRuntimeBinDirectory();
 278     SetDllDirectory(runtimeBin.c_str());
 279 #else
 280     javaLibrary.AddDependencies(
 281             platform.FilterOutRuntimeDependenciesForPlatform(
 282             platform.GetLibraryImports(libName)));
 283 #endif
 284     javaLibrary.Load(libName);
 285 }
 286 
 287 bool JavaVirtualMachine::launchVM(JavaOptions& options,
 288         std::list<TString>& vmargs) {
 289     Platform& platform = Platform::GetInstance();
 290     Package& package = Package::GetInstance();
 291 
 292 #ifdef MAC
 293     // Mac adds a ProcessSerialNumber to args when launched from .app
 294     // filter out the psn since they it's not expected in the app
 295     if (platform.IsMainThread() == false) {
 296         std::list<TString> loptions = options.ToList();
 297         vmargs.splice(vmargs.end(), loptions,
 298                 loptions.begin(), loptions.end());
 299     }
 300 #else
 301     std::list<TString> loptions = options.ToList();
 302     vmargs.splice(vmargs.end(), loptions, loptions.begin(), loptions.end());
 303 #endif




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "JavaVirtualMachine.h"
  27 #include "Platform.h"
  28 #include "PlatformString.h"
  29 #include "FilePath.h"
  30 #include "Package.h"

  31 #include "Helpers.h"
  32 #include "Messages.h"
  33 #include "Macros.h"

  34 
  35 #include "jni.h"
  36 
  37 #include <map>
  38 #include <list>
  39 #include <sstream>
  40 
  41 
  42 bool RunVM() {
  43     JavaVirtualMachine javavm;
  44 
  45     bool result = javavm.StartJVM();
  46 
  47     if (!result) {
  48         Platform& platform = Platform::GetInstance();
  49         platform.ShowMessage(_T("Failed to launch JVM\n"));
  50     }
  51 
  52     return result;
  53 }
  54 





























  55 //----------------------------------------------------------------------------
  56 
  57 JavaOptions::JavaOptions(): FOptions(NULL) {
  58 }
  59 
  60 JavaOptions::~JavaOptions() {
  61     if (FOptions != NULL) {
  62         for (unsigned int index = 0; index < GetCount(); index++) {
  63             delete[] FOptions[index].optionString;
  64         }
  65 
  66         delete[] FOptions;
  67     }
  68 }
  69 
  70 void JavaOptions::AppendValue(const TString Key, TString Value, void* Extra) {
  71     JavaOptionItem item;
  72     item.name = Key;
  73     item.value = Value;
  74     item.extraInfo = Extra;


 217 
 218     if (package.HasSplashScreen() == true) {
 219         options.AppendValue(TString(_T("-splash:"))
 220                 + package.GetSplashScreenFileName(), _T(""));
 221     }
 222 
 223     if (mainModule.empty() == true) {
 224         options.AppendValue(Helpers::ConvertJavaPathToId(mainClassName),
 225                 _T(""));
 226     } else {
 227         options.AppendValue(_T("-m"));
 228         options.AppendValue(mainModule);
 229     }
 230 
 231     return launchVM(options, vmargs);
 232 }
 233 
 234 void JavaVirtualMachine::configureLibrary() {
 235     Platform& platform = Platform::GetInstance();
 236     Package& package = Package::GetInstance();



 237     TString libName = package.GetJVMLibraryFileName();
 238     platform.addPlatformDependencies(&javaLibrary);











 239     javaLibrary.Load(libName);
 240 }
 241 
 242 bool JavaVirtualMachine::launchVM(JavaOptions& options,
 243         std::list<TString>& vmargs) {
 244     Platform& platform = Platform::GetInstance();
 245     Package& package = Package::GetInstance();
 246 
 247 #ifdef MAC
 248     // Mac adds a ProcessSerialNumber to args when launched from .app
 249     // filter out the psn since they it's not expected in the app
 250     if (platform.IsMainThread() == false) {
 251         std::list<TString> loptions = options.ToList();
 252         vmargs.splice(vmargs.end(), loptions,
 253                 loptions.begin(), loptions.end());
 254     }
 255 #else
 256     std::list<TString> loptions = options.ToList();
 257     vmargs.splice(vmargs.end(), loptions, loptions.begin(), loptions.end());
 258 #endif


< prev index next >