1 /* 2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 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 #ifndef JAVAVIRTUALMACHINE_H 27 #define JAVAVIRTUALMACHINE_H 28 29 30 #include "jni.h" 31 #include "Platform.h" 32 33 struct JavaOptionItem { 34 TString name; 35 TString value; 36 void* extraInfo; 37 }; 38 39 class JavaOptions { 40 private: 41 std::list<JavaOptionItem> FItems; 42 JavaVMOption* FOptions; 43 44 public: 45 JavaOptions(); 46 ~JavaOptions(); 47 48 void AppendValue(const TString Key, TString Value, void* Extra); 49 void AppendValue(const TString Key, TString Value); 50 void AppendValue(const TString Key); 51 void AppendValues(OrderedMap<TString, TString> Values); 52 void ReplaceValue(const TString Key, TString Value); 53 std::list<TString> ToList(); 54 size_t GetCount(); 55 }; 56 57 // Private typedef for function pointer casting 58 #define LAUNCH_FUNC "JLI_Launch" 59 60 typedef int (JNICALL *JVM_CREATE)(int argc, char ** argv, 61 int jargc, const char** jargv, 62 int appclassc, const char** appclassv, 63 const char* fullversion, 64 const char* dotversion, 65 const char* pname, 66 const char* lname, 67 jboolean javaargs, 68 jboolean cpwildcard, 69 jboolean javaw, 70 jint ergo); 71 72 class JavaLibrary : public Library { 73 JVM_CREATE FCreateProc; 74 JavaLibrary(const TString &FileName); 75 public: 76 JavaLibrary(); 77 bool JavaVMCreate(size_t argc, char *argv[]); 78 }; 79 80 class JavaVirtualMachine { 81 private: 82 JavaLibrary javaLibrary; 83 84 void configureLibrary(); 85 bool launchVM(JavaOptions& options, std::list<TString>& vmargs); 86 public: 87 JavaVirtualMachine(); 88 ~JavaVirtualMachine(void); 89 90 bool StartJVM(); 91 }; 92 93 bool RunVM(); 94 95 #endif // JAVAVIRTUALMACHINE_H