提交 4c8403fd 编写于 作者: P phh

Merge

...@@ -94,15 +94,15 @@ static int numOptions, maxOptions; ...@@ -94,15 +94,15 @@ static int numOptions, maxOptions;
* Prototypes for functions internal to launcher. * Prototypes for functions internal to launcher.
*/ */
static void SetClassPath(const char *s); static void SetClassPath(const char *s);
static void SetModulesBootClassPath(const char *s);
static void SelectVersion(int argc, char **argv, char **main_class); static void SelectVersion(int argc, char **argv, char **main_class);
static jboolean ParseArguments(int *pargc, char ***pargv, char **pjarfile, static jboolean ParseArguments(int *pargc, char ***pargv,
char **pclassname, int *pret, const char *jvmpath); int *pmode, char **pwhat,
int *pret, const char *jrepath);
static jboolean InitializeJVM(JavaVM **pvm, JNIEnv **penv, static jboolean InitializeJVM(JavaVM **pvm, JNIEnv **penv,
InvocationFunctions *ifn); InvocationFunctions *ifn);
static jstring NewPlatformString(JNIEnv *env, char *s); static jstring NewPlatformString(JNIEnv *env, char *s);
static jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc); static jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc);
static jclass LoadMainClass(JNIEnv *env, jboolean isJar, char *name); static jclass LoadMainClass(JNIEnv *env, int mode, char *name);
static void TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv); static void TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv);
static jboolean AddApplicationOptions(int cpathc, const char **cpathv); static jboolean AddApplicationOptions(int cpathc, const char **cpathv);
...@@ -164,11 +164,20 @@ static jlong initialHeapSize = 0; /* inital heap size */ ...@@ -164,11 +164,20 @@ static jlong initialHeapSize = 0; /* inital heap size */
int JNICALL JavaMain(void * args); /* entry point */ int JNICALL JavaMain(void * args); /* entry point */
enum LaunchMode { // cf. sun.launcher.LauncherHelper
LM_UNKNOWN = 0,
LM_CLASS,
LM_JAR
};
static const char *launchModeNames[]
= { "Unknown", "Main class", "JAR file" };
typedef struct { typedef struct {
int argc; int argc;
char ** argv; char **argv;
char * jarfile; int mode;
char * classname; char *what;
InvocationFunctions ifn; InvocationFunctions ifn;
} JavaMainArgs; } JavaMainArgs;
...@@ -189,8 +198,8 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */ ...@@ -189,8 +198,8 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */
jint ergo /* ergonomics class policy */ jint ergo /* ergonomics class policy */
) )
{ {
char *jarfile = 0; int mode = LM_UNKNOWN;
char *classname = 0; char *what = NULL;
char *cpath = 0; char *cpath = 0;
char *main_class = NULL; char *main_class = NULL;
int ret; int ret;
...@@ -277,24 +286,21 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */ ...@@ -277,24 +286,21 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */
SetClassPath(cpath); SetClassPath(cpath);
} }
/* /* Parse command line options; if the return value of
* Parse command line options; if the return value of
* ParseArguments is false, the program should exit. * ParseArguments is false, the program should exit.
*/ */
if (!ParseArguments(&argc, &argv, &jarfile, &classname, &ret, jvmpath)) { if (!ParseArguments(&argc, &argv, &mode, &what, &ret, jrepath))
{
return(ret); return(ret);
} }
/* Set bootclasspath for modules */
SetModulesBootClassPath(jrepath);
/* Override class path if -jar flag was specified */ /* Override class path if -jar flag was specified */
if (jarfile != 0) { if (mode == LM_JAR) {
SetClassPath(jarfile); SetClassPath(what); /* Override class path */
} }
/* set the -Dsun.java.command pseudo property */ /* set the -Dsun.java.command pseudo property */
SetJavaCommandLineProp(classname, jarfile, argc, argv); SetJavaCommandLineProp(what, argc, argv);
/* Set the -Dsun.java.launcher pseudo property */ /* Set the -Dsun.java.launcher pseudo property */
SetJavaLauncherProp(); SetJavaLauncherProp();
...@@ -305,7 +311,7 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */ ...@@ -305,7 +311,7 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */
/* Show the splash screen if needed */ /* Show the splash screen if needed */
ShowSplashScreen(); ShowSplashScreen();
return ContinueInNewThread(&ifn, argc, argv, jarfile, classname, ret); return ContinueInNewThread(&ifn, argc, argv, mode, what, ret);
} }
/* /*
...@@ -353,13 +359,13 @@ JavaMain(void * _args) ...@@ -353,13 +359,13 @@ JavaMain(void * _args)
JavaMainArgs *args = (JavaMainArgs *)_args; JavaMainArgs *args = (JavaMainArgs *)_args;
int argc = args->argc; int argc = args->argc;
char **argv = args->argv; char **argv = args->argv;
char *jarfile = args->jarfile; int mode = args->mode;
char *classname = args->classname; char *what = args->what;
InvocationFunctions ifn = args->ifn; InvocationFunctions ifn = args->ifn;
JavaVM *vm = 0; JavaVM *vm = 0;
JNIEnv *env = 0; JNIEnv *env = 0;
jclass mainClass; jclass mainClass = NULL;
jmethodID mainID; jmethodID mainID;
jobjectArray mainArgs; jobjectArray mainArgs;
int ret = 0; int ret = 0;
...@@ -385,7 +391,7 @@ JavaMain(void * _args) ...@@ -385,7 +391,7 @@ JavaMain(void * _args)
CHECK_EXCEPTION_LEAVE(1); CHECK_EXCEPTION_LEAVE(1);
} }
/* If the user specified neither a class name nor a JAR file */ /* If the user specified neither a class name nor a JAR file */
if (printXUsage || printUsage || (jarfile == 0 && classname == 0)) { if (printXUsage || printUsage || what == 0 || mode == LM_UNKNOWN) {
PrintUsage(env, printXUsage); PrintUsage(env, printXUsage);
CHECK_EXCEPTION_LEAVE(1); CHECK_EXCEPTION_LEAVE(1);
LEAVE(); LEAVE();
...@@ -399,11 +405,11 @@ JavaMain(void * _args) ...@@ -399,11 +405,11 @@ JavaMain(void * _args)
(long)(jint)Counter2Micros(end-start)); (long)(jint)Counter2Micros(end-start));
} }
/* At this stage, argc/argv have the applications' arguments */ /* At this stage, argc/argv have the application's arguments */
if (JLI_IsTraceLauncher()){ if (JLI_IsTraceLauncher()){
int i; int i;
printf("Main-Class is '%s'\n", classname ? classname : ""); printf("%s is '%s'\n", launchModeNames[mode], what);
printf("Apps' argc is %d\n", argc); printf("App's argc is %d\n", argc);
for (i=0; i < argc; i++) { for (i=0; i < argc; i++) {
printf(" argv[%2d] = '%s'\n", i, argv[i]); printf(" argv[%2d] = '%s'\n", i, argv[i]);
} }
...@@ -431,11 +437,7 @@ JavaMain(void * _args) ...@@ -431,11 +437,7 @@ JavaMain(void * _args)
* 2) Remove the vestages of maintaining main_class through * 2) Remove the vestages of maintaining main_class through
* the environment (and remove these comments). * the environment (and remove these comments).
*/ */
if (jarfile != 0) { mainClass = LoadMainClass(env, mode, what);
mainClass = LoadMainClass(env, JNI_TRUE, jarfile);
} else {
mainClass = LoadMainClass(env, JNI_FALSE, classname);
}
CHECK_EXCEPTION_NULL_LEAVE(mainClass); CHECK_EXCEPTION_NULL_LEAVE(mainClass);
/* /*
...@@ -718,44 +720,6 @@ SetClassPath(const char *s) ...@@ -718,44 +720,6 @@ SetClassPath(const char *s)
JLI_MemFree((char *) s); JLI_MemFree((char *) s);
} }
/*
* Set the bootclasspath for modules.
* A temporary workaround until jigsaw is integrated into JDK 7.
*/
static void
SetModulesBootClassPath(const char *jrepath)
{
char *def, *s;
char pathname[MAXPATHLEN];
const char separator[] = { FILE_SEPARATOR, '\0' };
const char *orig = jrepath;
static const char format[] = "-Xbootclasspath/p:%s";
struct stat statbuf;
/* return if jre/lib/rt.jar exists */
JLI_Snprintf(pathname, sizeof(pathname), "%s%slib%srt.jar", jrepath, separator, separator);
if (stat(pathname, &statbuf) == 0) {
return;
}
/* return if jre/classes exists */
JLI_Snprintf(pathname, sizeof(pathname), "%s%sclasses", jrepath, separator);
if (stat(pathname, &statbuf) == 0) {
return;
}
/* modularized jre */
JLI_Snprintf(pathname, sizeof(pathname), "%s%slib%s*", jrepath, separator, separator);
s = (char *) JLI_WildcardExpandClasspath(pathname);
def = JLI_MemAlloc(sizeof(format)
- 2 /* strlen("%s") */
+ JLI_StrLen(s));
sprintf(def, format, s);
AddOption(def, NULL);
if (s != orig)
JLI_MemFree((char *) s);
}
/* /*
* The SelectVersion() routine ensures that an appropriate version of * The SelectVersion() routine ensures that an appropriate version of
* the JRE is running. The specification for the appropriate version * the JRE is running. The specification for the appropriate version
...@@ -1004,12 +968,13 @@ SelectVersion(int argc, char **argv, char **main_class) ...@@ -1004,12 +968,13 @@ SelectVersion(int argc, char **argv, char **main_class)
* process return value) is set to 0 for a normal exit. * process return value) is set to 0 for a normal exit.
*/ */
static jboolean static jboolean
ParseArguments(int *pargc, char ***pargv, char **pjarfile, ParseArguments(int *pargc, char ***pargv,
char **pclassname, int *pret, const char *jvmpath) int *pmode, char **pwhat,
int *pret, const char *jrepath)
{ {
int argc = *pargc; int argc = *pargc;
char **argv = *pargv; char **argv = *pargv;
jboolean jarflag = JNI_FALSE; int mode = LM_UNKNOWN;
char *arg; char *arg;
*pret = 0; *pret = 0;
...@@ -1019,10 +984,11 @@ ParseArguments(int *pargc, char ***pargv, char **pjarfile, ...@@ -1019,10 +984,11 @@ ParseArguments(int *pargc, char ***pargv, char **pjarfile,
if (JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) { if (JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) {
ARG_CHECK (argc, ARG_ERROR1, arg); ARG_CHECK (argc, ARG_ERROR1, arg);
SetClassPath(*argv); SetClassPath(*argv);
mode = LM_CLASS;
argv++; --argc; argv++; --argc;
} else if (JLI_StrCmp(arg, "-jar") == 0) { } else if (JLI_StrCmp(arg, "-jar") == 0) {
ARG_CHECK (argc, ARG_ERROR2, arg); ARG_CHECK (argc, ARG_ERROR2, arg);
jarflag = JNI_TRUE; mode = LM_JAR;
} else if (JLI_StrCmp(arg, "-help") == 0 || } else if (JLI_StrCmp(arg, "-help") == 0 ||
JLI_StrCmp(arg, "-h") == 0 || JLI_StrCmp(arg, "-h") == 0 ||
JLI_StrCmp(arg, "-?") == 0) { JLI_StrCmp(arg, "-?") == 0) {
...@@ -1102,19 +1068,24 @@ ParseArguments(int *pargc, char ***pargv, char **pjarfile, ...@@ -1102,19 +1068,24 @@ ParseArguments(int *pargc, char ***pargv, char **pjarfile,
} }
if (--argc >= 0) { if (--argc >= 0) {
if (jarflag) { *pwhat = *argv++;
*pjarfile = *argv++;
*pclassname = NULL;
} else {
*pjarfile = NULL;
*pclassname = *argv++;
} }
if (*pwhat == NULL) {
*pret = 1;
} else if (mode == LM_UNKNOWN) {
/* default to LM_CLASS if -jar and -cp option are
* not specified */
mode = LM_CLASS;
}
if (argc >= 0) {
*pargc = argc; *pargc = argc;
*pargv = argv; *pargv = argv;
} }
if (*pjarfile == NULL && *pclassname == NULL) {
*pret = 1; *pmode = mode;
}
return JNI_TRUE; return JNI_TRUE;
} }
...@@ -1263,7 +1234,7 @@ NewPlatformStringArray(JNIEnv *env, char **strv, int strc) ...@@ -1263,7 +1234,7 @@ NewPlatformStringArray(JNIEnv *env, char **strv, int strc)
* call it for more details refer to the java implementation. * call it for more details refer to the java implementation.
*/ */
static jclass static jclass
LoadMainClass(JNIEnv *env, jboolean isJar, char *name) LoadMainClass(JNIEnv *env, int mode, char *name)
{ {
jclass cls; jclass cls;
jmethodID mid; jmethodID mid;
...@@ -1276,9 +1247,9 @@ LoadMainClass(JNIEnv *env, jboolean isJar, char *name) ...@@ -1276,9 +1247,9 @@ LoadMainClass(JNIEnv *env, jboolean isJar, char *name)
} }
NULL_CHECK0(cls = FindBootStrapClass(env, "sun/launcher/LauncherHelper")); NULL_CHECK0(cls = FindBootStrapClass(env, "sun/launcher/LauncherHelper"));
NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls, "checkAndLoadMain", NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls, "checkAndLoadMain",
"(ZZLjava/lang/String;)Ljava/lang/Object;")); "(ZILjava/lang/String;)Ljava/lang/Class;"));
str = (*env)->NewStringUTF(env, name); str = (*env)->NewStringUTF(env, name);
result = (*env)->CallStaticObjectMethod(env, cls, mid, JNI_TRUE, isJar, str); result = (*env)->CallStaticObjectMethod(env, cls, mid, JNI_TRUE, mode, str);
if (JLI_IsTraceLauncher()) { if (JLI_IsTraceLauncher()) {
end = CounterGet(); end = CounterGet();
...@@ -1424,8 +1395,7 @@ AddApplicationOptions(int cpathc, const char **cpathv) ...@@ -1424,8 +1395,7 @@ AddApplicationOptions(int cpathc, const char **cpathv)
* property is not exported by HotSpot to the Java layer. * property is not exported by HotSpot to the Java layer.
*/ */
void void
SetJavaCommandLineProp(char *classname, char *jarfile, SetJavaCommandLineProp(char *what, int argc, char **argv)
int argc, char **argv)
{ {
int i = 0; int i = 0;
...@@ -1433,22 +1403,17 @@ SetJavaCommandLineProp(char *classname, char *jarfile, ...@@ -1433,22 +1403,17 @@ SetJavaCommandLineProp(char *classname, char *jarfile,
char* javaCommand = NULL; char* javaCommand = NULL;
char* dashDstr = "-Dsun.java.command="; char* dashDstr = "-Dsun.java.command=";
if (classname == NULL && jarfile == NULL) { if (what == NULL) {
/* unexpected, one of these should be set. just return without /* unexpected, one of these should be set. just return without
* setting the property * setting the property
*/ */
return; return;
} }
/* if the class name is not set, then use the jarfile name */
if (classname == NULL) {
classname = jarfile;
}
/* determine the amount of memory to allocate assuming /* determine the amount of memory to allocate assuming
* the individual components will be space separated * the individual components will be space separated
*/ */
len = JLI_StrLen(classname); len = JLI_StrLen(what);
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
len += JLI_StrLen(argv[i]) + 1; len += JLI_StrLen(argv[i]) + 1;
} }
...@@ -1459,7 +1424,7 @@ SetJavaCommandLineProp(char *classname, char *jarfile, ...@@ -1459,7 +1424,7 @@ SetJavaCommandLineProp(char *classname, char *jarfile,
/* build the -D string */ /* build the -D string */
*javaCommand = '\0'; *javaCommand = '\0';
JLI_StrCat(javaCommand, dashDstr); JLI_StrCat(javaCommand, dashDstr);
JLI_StrCat(javaCommand, classname); JLI_StrCat(javaCommand, what);
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
/* the components of the string are space separated. In /* the components of the string are space separated. In
...@@ -1479,7 +1444,8 @@ SetJavaCommandLineProp(char *classname, char *jarfile, ...@@ -1479,7 +1444,8 @@ SetJavaCommandLineProp(char *classname, char *jarfile,
* JVM would like to know if it's created by a standard Sun launcher, or by * JVM would like to know if it's created by a standard Sun launcher, or by
* user native application, the following property indicates the former. * user native application, the following property indicates the former.
*/ */
void SetJavaLauncherProp() { void
SetJavaLauncherProp() {
AddOption("-Dsun.java.launcher=SUN_STANDARD", NULL); AddOption("-Dsun.java.launcher=SUN_STANDARD", NULL);
} }
...@@ -1913,8 +1879,8 @@ IsWildCardEnabled() ...@@ -1913,8 +1879,8 @@ IsWildCardEnabled()
} }
static int static int
ContinueInNewThread(InvocationFunctions* ifn, int argc, ContinueInNewThread(InvocationFunctions* ifn, int argc, char **argv,
char **argv, char *jarfile, char *classname, int ret) int mode, char *what, int ret)
{ {
/* /*
...@@ -1938,8 +1904,8 @@ ContinueInNewThread(InvocationFunctions* ifn, int argc, ...@@ -1938,8 +1904,8 @@ ContinueInNewThread(InvocationFunctions* ifn, int argc,
args.argc = argc; args.argc = argc;
args.argv = argv; args.argv = argv;
args.jarfile = jarfile; args.mode = mode;
args.classname = classname; args.what = what;
args.ifn = *ifn; args.ifn = *ifn;
rslt = ContinueInNewThread0(JavaMain, threadStackSize, (void*)&args); rslt = ContinueInNewThread0(JavaMain, threadStackSize, (void*)&args);
......
...@@ -153,7 +153,7 @@ int ContinueInNewThread0(int (JNICALL *continuation)(void *), ...@@ -153,7 +153,7 @@ int ContinueInNewThread0(int (JNICALL *continuation)(void *),
/* sun.java.launcher.* platform properties. */ /* sun.java.launcher.* platform properties. */
void SetJavaLauncherPlatformProps(void); void SetJavaLauncherPlatformProps(void);
void SetJavaCommandLineProp(char* classname, char* jarfile, int argc, char** argv); void SetJavaCommandLineProp(char* what, int argc, char** argv);
void SetJavaLauncherProp(void); void SetJavaLauncherProp(void);
/* /*
...@@ -178,8 +178,9 @@ jint GetErgoPolicy(); ...@@ -178,8 +178,9 @@ jint GetErgoPolicy();
jboolean ServerClassMachine(); jboolean ServerClassMachine();
static int ContinueInNewThread(InvocationFunctions* ifn, int argc, char** argv, static int ContinueInNewThread(InvocationFunctions* ifn,
char* jarfile, char* classname, int ret); int argc, char** argv,
int mode, char *what, int ret);
/* /*
* Initialize platform specific settings * Initialize platform specific settings
......
...@@ -677,8 +677,7 @@ class InetAddress implements java.io.Serializable { ...@@ -677,8 +677,7 @@ class InetAddress implements java.io.Serializable {
static InetAddressImpl impl; static InetAddressImpl impl;
private static HashMap<String, InetAddress[]> lookupTable private static final HashMap<String, Void> lookupTable = new HashMap<>();
= new HashMap<String, InetAddress[]>();
/** /**
* Represents a cache entry * Represents a cache entry
...@@ -737,7 +736,7 @@ class InetAddress implements java.io.Serializable { ...@@ -737,7 +736,7 @@ class InetAddress implements java.io.Serializable {
// As we iterate in insertion order we can // As we iterate in insertion order we can
// terminate when a non-expired entry is found. // terminate when a non-expired entry is found.
LinkedList<String> expired = new LinkedList<String>(); LinkedList<String> expired = new LinkedList<>();
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
for (String key : cache.keySet()) { for (String key : cache.keySet()) {
CacheEntry entry = cache.get(key); CacheEntry entry = cache.get(key);
...@@ -1227,6 +1226,7 @@ class InetAddress implements java.io.Serializable { ...@@ -1227,6 +1226,7 @@ class InetAddress implements java.io.Serializable {
// lookupTable and return null so the // lookupTable and return null so the
// following code would do a lookup itself. // following code would do a lookup itself.
if ((addresses = checkLookupTable(host)) == null) { if ((addresses = checkLookupTable(host)) == null) {
try {
// This is the first thread which looks up the addresses // This is the first thread which looks up the addresses
// this host or the cache entry for this host has been // this host or the cache entry for this host has been
// expired so this thread should do the lookup. // expired so this thread should do the lookup.
...@@ -1258,12 +1258,13 @@ class InetAddress implements java.io.Serializable { ...@@ -1258,12 +1258,13 @@ class InetAddress implements java.io.Serializable {
// Cache the addresses. // Cache the addresses.
cacheAddresses(host, addresses, success); cacheAddresses(host, addresses, success);
// Delete the host from the lookupTable, and
// notify all threads waiting for the monitor
// for lookupTable.
updateLookupTable(host);
if (!success && ex != null) if (!success && ex != null)
throw ex; throw ex;
} finally {
// Delete host from the lookupTable and notify
// all threads waiting on the lookupTable monitor.
updateLookupTable(host);
}
} }
return addresses; return addresses;
...@@ -1271,16 +1272,13 @@ class InetAddress implements java.io.Serializable { ...@@ -1271,16 +1272,13 @@ class InetAddress implements java.io.Serializable {
private static InetAddress[] checkLookupTable(String host) { private static InetAddress[] checkLookupTable(String host) {
// make sure addresses is null.
InetAddress[] addresses = null;
synchronized (lookupTable) { synchronized (lookupTable) {
// If the host isn't in the lookupTable, add it in the // If the host isn't in the lookupTable, add it in the
// lookuptable and return null. The caller should do // lookuptable and return null. The caller should do
// the lookup. // the lookup.
if (lookupTable.containsKey(host) == false) { if (lookupTable.containsKey(host) == false) {
lookupTable.put(host, null); lookupTable.put(host, null);
return addresses; return null;
} }
// If the host is in the lookupTable, it means that another // If the host is in the lookupTable, it means that another
...@@ -1298,10 +1296,11 @@ class InetAddress implements java.io.Serializable { ...@@ -1298,10 +1296,11 @@ class InetAddress implements java.io.Serializable {
// the host. This thread should retry to get the addresses // the host. This thread should retry to get the addresses
// from the addressCache. If it doesn't get the addresses from // from the addressCache. If it doesn't get the addresses from
// the cache, it will try to look up the addresses itself. // the cache, it will try to look up the addresses itself.
addresses = getCachedAddresses(host); InetAddress[] addresses = getCachedAddresses(host);
if (addresses == null) { if (addresses == null) {
synchronized (lookupTable) { synchronized (lookupTable) {
lookupTable.put(host, null); lookupTable.put(host, null);
return null;
} }
} }
......
...@@ -401,6 +401,14 @@ public enum LauncherHelper { ...@@ -401,6 +401,14 @@ public enum LauncherHelper {
} }
} }
// From src/share/bin/java.c:
// enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR };
private static final int LM_UNKNOWN = 0;
private static final int LM_CLASS = 1;
private static final int LM_JAR = 2;
/** /**
* This method does the following: * This method does the following:
* 1. gets the classname from a Jar's manifest, if necessary * 1. gets the classname from a Jar's manifest, if necessary
...@@ -420,24 +428,40 @@ public enum LauncherHelper { ...@@ -420,24 +428,40 @@ public enum LauncherHelper {
* @return * @return
* @throws java.io.IOException * @throws java.io.IOException
*/ */
public static Object checkAndLoadMain(boolean printToStderr, public static Class<?> checkAndLoadMain(boolean printToStderr,
boolean isJar, String name) throws IOException { int mode,
String what) throws IOException
{
ClassLoader ld = ClassLoader.getSystemClassLoader();
// get the class name // get the class name
String classname = (isJar) ? getMainClassFromJar(name) : name; String cn = null;
classname = classname.replace('/', '.'); switch (mode) {
ClassLoader loader = ClassLoader.getSystemClassLoader(); case LM_CLASS:
Class<?> clazz = null; cn = what;
break;
case LM_JAR:
cn = getMainClassFromJar(what);
break;
default:
throw new InternalError("" + mode + ": Unknown launch mode");
}
cn = cn.replace('/', '.');
PrintStream ostream = (printToStderr) ? System.err : System.out; PrintStream ostream = (printToStderr) ? System.err : System.out;
Class<?> c = null;
try { try {
clazz = loader.loadClass(classname); c = ld.loadClass(cn);
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
ostream.println(getLocalizedMessage("java.launcher.cls.error1", classname)); ostream.println(getLocalizedMessage("java.launcher.cls.error1",
NoClassDefFoundError ncdfe = new NoClassDefFoundError(classname); cn));
NoClassDefFoundError ncdfe = new NoClassDefFoundError(cn);
ncdfe.initCause(cnfe); ncdfe.initCause(cnfe);
throw ncdfe; throw ncdfe;
} }
signatureDiagnostic(ostream, clazz); signatureDiagnostic(ostream, c);
return clazz; return c;
} }
static void signatureDiagnostic(PrintStream ostream, Class<?> clazz) { static void signatureDiagnostic(PrintStream ostream, Class<?> clazz) {
......
...@@ -29,12 +29,14 @@ ...@@ -29,12 +29,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
// To ensure winsock2.h is used, it has to be included ahead of
// windows.h, which includes winsock.h by default.
#include <winsock2.h>
#include <windows.h> #include <windows.h>
#include <io.h> #include <io.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <mmsystem.h> #include <mmsystem.h>
#include <winsock2.h>
#include <fcntl.h> #include <fcntl.h>
#include <process.h> #include <process.h>
...@@ -147,7 +149,7 @@ md_seek(int filedes, jlong pos) ...@@ -147,7 +149,7 @@ md_seek(int filedes, jlong pos)
void void
md_close(int filedes) md_close(int filedes)
{ {
(void)close(filedes); (void)closesocket(filedes);
} }
int int
......
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions
Simple1NameServiceDescriptor
Simple2NameServiceDescriptor
...@@ -25,15 +25,17 @@ ...@@ -25,15 +25,17 @@
* @test * @test
* @bug 4762344 * @bug 4762344
* @summary 2nd nameservice provider is non functional * @summary 2nd nameservice provider is non functional
* @build B4762344 SimpleNameService Simple1NameServiceDescriptor Simple2NameServiceDescriptor * @compile -XDignore.symbol.file=true SimpleNameService.java
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=simple1,sun -Dsun.net.spi.nameservice.provider.2=simple2,sun B4762344 * Simple1NameServiceDescriptor.java
* Simple2NameServiceDescriptor.java
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=simple1,sun -Dsun.net.spi.nameservice.provider.2=simple2,sun Providers
*/ */
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
public class B4762344 { public class Providers {
private static String[][] hostnames = new String[][] { private static String[][] hostnames = new String[][] {
// both providers know this host, but with different address // both providers know this host, but with different address
new String[] {"blade", "10.0.0.1"}, new String[] {"blade", "10.0.0.1"},
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 7012768
* @compile -XDignore.symbol.file=true ThrowingNameService.java
* ThrowingNameServiceDescriptor.java
* @run main/othervm/timeout=30 -Dsun.net.spi.nameservice.provider.1=throwing,sun Hang
* @summary InetAddress lookupTable leaks/deadlocks when using unsupported
* name service spi
*/
import java.net.InetAddress;
public class Hang {
public static void main(String[] args) throws Exception {
try {
// 1st attempt - IllegalStateException caught below
InetAddress.getByName("host.company.com");
} catch (IllegalStateException e) { }
// 2nd attempt - Stuck here forever if bug exists
InetAddress.getByName("host.company.com");
}
}
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
ThrowingNameServiceDescriptor
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.net.InetAddress;
import java.net.UnknownHostException;
import sun.net.spi.nameservice.NameService;
public class ThrowingNameService implements NameService {
static boolean firstCall = true;
@Override
public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException {
if (firstCall) {
firstCall = false;
// throw unchecked exception first time round
throw new IllegalStateException();
}
// return any valid address
return new InetAddress[] { InetAddress.getLoopbackAddress() };
}
@Override
public String getHostByAddr(byte[] addr) throws UnknownHostException {
throw new IllegalStateException();
}
}
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import sun.net.spi.nameservice.*;
public class ThrowingNameServiceDescriptor implements NameServiceDescriptor {
public NameService createNameService() {
return new ThrowingNameService();
}
@Override
public String getProviderName() {
return "sun";
}
@Override
public String getType() {
return "throwing";
}
}
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
* @summary Check that InetAddress doesn't continue to throw UHE * @summary Check that InetAddress doesn't continue to throw UHE
* after the name service has recovered and the negative ttl * after the name service has recovered and the negative ttl
* on the initial lookup has expired. * on the initial lookup has expired.
* * @compile -XDignore.symbol.file=true SimpleNameService.java
* @build CacheTest SimpleNameService SimpleNameServiceDescriptor * SimpleNameServiceDescriptor.java
* @run main/othervm/timeout=200 -Dsun.net.spi.nameservice.provider.1=simple,sun CacheTest * @run main/othervm/timeout=200 -Dsun.net.spi.nameservice.provider.1=simple,sun CacheTest
*/ */
import java.net.InetAddress; import java.net.InetAddress;
......
...@@ -25,15 +25,15 @@ ...@@ -25,15 +25,15 @@
* @bug 6442088 * @bug 6442088
* @summary Change default DNS caching behavior for code not running under * @summary Change default DNS caching behavior for code not running under
* security manager. * security manager.
* * @compile -XDignore.symbol.file=true SimpleNameService.java
* @build B6442088 SimpleNameService SimpleNameServiceDescriptor * SimpleNameServiceDescriptor.java
* @run main/othervm/timeout=200 -Dsun.net.inetaddr.ttl=20 -Dsun.net.spi.nameservice.provider.1=simple,sun B6442088 * @run main/othervm/timeout=200 -Dsun.net.inetaddr.ttl=20 -Dsun.net.spi.nameservice.provider.1=simple,sun DefaultCaching
*/ */
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.security.Security; import java.security.Security;
public class B6442088 { public class DefaultCaching {
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
......
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
SimpleNameServiceDescriptor # name service provider descriptor
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册