harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Deven You <devyo...@gmail.com>
Subject Re: about java -version issue for harmony java launcher
Date Fri, 20 Mar 2009 04:24:14 GMT
It's great, I have tested it and am looking forward to committing it to
classlib.

2009/3/20 Oliver Deakin <oliver.deakin@googlemail.com>

> I have attached a short patch for a first shot at implementing such a
> class, with the changes to the launcher also. With this patch you can type
> -version to get normal version string information (from Java properties, so
> may not get the full version info from drlvm yet) and -version:extended to
> get the full manifest version information also. Perhaps it could be
> formatted better, but it's a starting place ;) If this seems along the right
> lines, Ill commit it after M9 and we can tweak it as we see fit.
>
> Regards,
> Oliver
>
>
>
> Regis wrote:
>
>> Deven You wrote:
>>
>>> 2009/3/19 Oliver Deakin <oliver.deakin@googlemail.com>
>>>
>>>  That sounds similar to the solution I was thinking of as well - we could
>>>> create an internal Harmony class that looks up properties/version values
>>>> and
>>>> constructs an output version information string from them. This class
>>>> would
>>>> be invoked by the launcher if the -version option is found anywhere in
>>>> the
>>>> command line options.
>>>>
>>>>
>>>  I see that J9 puts it's full version information in the java.fullversion
>>>> and java.vm.info properties, but these are non-standard. I cannot see
>>>> the
>>>> version info that drlvm prints when passed -version in any Java
>>>> property.
>>>> The standard Java properties only provide high level version information
>>>> (not full component breakdown, build dates, repository revision etc.).
>>>> Perhaps drlvm could also set the java.fullversion (or some other)
>>>> property -
>>>> then the class that puts together the version information could look at
>>>> this
>>>> property first and if it exists use it, otherwise fall back to the
>>>> standard,
>>>> less detailed, properties (java.vm.version, java.vm.name etc.).
>>>>
>>>> For the class libraries, I agree that a per module version info might be
>>>> quite useful - I guess we would want to output the Bundle-Name and
>>>> Bundle-Version from each jar manifest?
>>>>
>>>> Regards,
>>>> Oliver
>>>>
>>>> I agree this opinion and I suggest may we use another option like
>>>>
>>> -classlibversion to show the classlib version information.
>>>
>>
>> It's a good idea, -version should show brief information about classlib,
>> like svn revision, build time, -classlibversion show all detail informations
>> of each modules. It could be a Harmony extension :)
>>
>>
>>>  Tim Ellison wrote:
>>>>
>>>>  Deven You wrote:
>>>>>
>>>>>
>>>>>   Harmony java launcher  "java -version" command can not work with IBM
>>>>>> J9
>>>>>> VM26 . The error result is as below:
>>>>>>
>>>>>>  ../jres/see/bin/java -version
>>>>>> Apache Harmony Launcher : (c) Copyright 1991, 2008 The Apache Software
>>>>>> Foundation or its licensors, as applicable.
>>>>>> JVMJ9VM007E Command-line option unrecognised: -version
>>>>>> HMYEXEL062E Internal VM error: Failed to create Java VM
>>>>>> FAILED to invoke JVM
>>>>>> This issue occurs on both linux and windows x86 platform.
>>>>>>
>>>>>>  I find our laucher just invoke the mothod JNI_CreateJavaVM()  of
 vm
>>>>>> which
>>>>>> on j9 vm does not deal with -version option according to JNI
>>>>>> Specification.
>>>>>> the specification says:
>>>>>> "All Java virtual machine implementations must recognize the following
>>>>>> set
>>>>>> of standard options:  ..."
>>>>>> it lists:
>>>>>>  -D<name><value>
>>>>>>  -verbose
>>>>>>  vfprintf
>>>>>>  exit
>>>>>>  abort
>>>>>>
>>>>>> It then goes on to stay:
>>>>>> "In addition, virtual machine implementations may support their own
>>>>>> set
>>>>>> of
>>>>>> implementation-dependent option strings.  Implementation-dependent
>>>>>> option
>>>>>> strings must begin with "-X" or an underscore."
>>>>>> Any other option is non-standard.
>>>>>>
>>>>>> but for DRLVM, seems its JNI_CreateJavaVM() does not comply with
JNI
>>>>>> Specification and support -version option.the result is below:
>>>>>>
>>>>>> Apache Harmony Launcher : (c) Copyright 1991, 2008 The Apache Software
>>>>>> Foundation or its licensors, as applicable.
>>>>>> java version "1.5.0"
>>>>>> pre-alpha : not complete or compatible
>>>>>> svn = r745401, (Feb 18 2009), Windows/ia32/msvc 1310, release build
>>>>>> http://harmony.apache.org.
>>>>>> but there is still no vm version info.
>>>>>>
>>>>>> I suggest our java launcher should not pass -version or other
>>>>>> non-standarad
>>>>>> options  to vm interface JNI_CreateJavaVM(), instead we should make
a
>>>>>> general solution to deal with them, maybe call certain methods in
jre
>>>>>> tool
>>>>>> package. so that  our java laucher can work well on different vms.
>>>>>>
>>>>>>
>>>>>>  Sounds reasonable to me.
>>>>>
>>>>> A basic implementation would create the VM then query the values in
>>>>> java.vm.version etc and print those, a more sophisticated (and longer
>>>>> running<g>) implementation would run a Java class and pull out
the VM
>>>>> version plus version information from our class library JARs too.
>>>>>
>>>>> (We would need to define the SVN build info as a property too so it can
>>>>> be picked up from Java)
>>>>>
>>>>> Regards,
>>>>> Tim
>>>>>
>>>>>
>>>>>
>>>>>  --
>>>> Oliver Deakin
>>>> Unless stated otherwise above:
>>>> IBM United Kingdom Limited - Registered in England and Wales with number
>>>> 741598. Registered office: PO Box 41, North Harbour, Portsmouth,
>>>> Hampshire
>>>> PO6 3AU
>>>>
>>>>
>>>>
>>>
>>
>>
> --
> Oliver Deakin
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number
> 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire
> PO6 3AU
>
>
> Index: src/main/java/org/apache/harmony/luni/util/Version.java
> ===================================================================
> --- src/main/java/org/apache/harmony/luni/util/Version.java     (revision
> 0)
> +++ src/main/java/org/apache/harmony/luni/util/Version.java     (revision
> 0)
> @@ -0,0 +1,86 @@
> +package org.apache.harmony.luni.util;
> +
> +import java.util.StringTokenizer;
> +import java.util.Iterator;
> +import java.util.jar.*;
> +import java.io.IOException;
> +
> +class Version {
> +    /*
> +     * Display VM version information
> +     */
> +    private static void displayVMVersion() {
> +        String version = System.getProperty("java.version");
> +        if (version != null) System.out.println("java version \"" +
> version + "\"");
> +
> +        String name = System.getProperty("java.runtime.name");
> +        version = System.getProperty("java.runtime.version");
> +
> +        if (name != null) {
> +            if (version != null) name = name + " (" + version + ")";
> +            System.out.println(name);
> +        }
> +
> +        name = System.getProperty("java.vm.name");
> +        version = System.getProperty("java.vm.version");
> +        if (name != null) {
> +            if (version != null) name = name + " (" + version + ")";
> +            System.out.println(name);
> +        }
> +
> +        name = System.getProperty("java.fullversion");
> +        if (name != null) System.out.println(name);
> +    }
> +
> +    /*
> +     * Display class library version information
> +     */
> +    private static void displayClasslibVersion() {
> +        // Get the bootclasspath and tokenise for each jar file
> +        String bootclasspath =
> System.getProperty("org.apache.harmony.boot.class.path");
> +        if (bootclasspath == null) return;
> +
> +        StringTokenizer tokenizer = new StringTokenizer(bootclasspath,
> System.getProperty("path.separator"));
> +
> +        while (tokenizer.hasMoreTokens()) {
> +            String jarPath = tokenizer.nextToken();
> +
> +            // If the current path is not a jar file, then continue
> iteration through tokens
> +            if (!jarPath.endsWith(".jar")) continue;
> +
> +            // Get the jar manifest and find it's name and version info
> +            JarFile jarFile;
> +            Manifest manifest;
> +            try {
> +                jarFile = new JarFile(jarPath);
> +                manifest = jarFile.getManifest();
> +            } catch (IOException e) {
> +                // We have hit an exception - just carry onto the next jar
> file
> +                continue;
> +            }
> +
> +            // Get the manifest attributes and output those we are
> interested in
> +            Attributes attributes = manifest.getMainAttributes();
> +            if (attributes == null) continue;
> +
> +            String bundleName = attributes.getValue("Bundle-Name");
> +            if (bundleName == null) continue;
> +            String bundleVersion = attributes.getValue("Bundle-Version");
> +            if (bundleVersion == null) continue;
> +
> +            System.out.println(jarPath + " " + bundleName + " " +
> bundleVersion);
> +        }
> +
> +    }
> +
> +    public static void version(String versionOpt) {
> +        if (versionOpt.equals("-version")) {
> +            displayVMVersion();
> +        } else if (versionOpt.equals("-version:extended")) {
> +            displayVMVersion();
> +            displayClasslibVersion();
> +        } else {
> +            System.out.println("Option " + versionOpt + " unrecognised -
> please use -version or -version:extended");
> +        }
> +    }
> +}
>
> Property changes on:
> src\main\java\org\apache\harmony\luni\util\Version.java
> ___________________________________________________________________
> Name: svn:eol-style
>   + native
>
> Index: src/main/native/launcher/shared/main.c
> ===================================================================
> --- src/main/native/launcher/shared/main.c      (revision 749575)
> +++ src/main/native/launcher/shared/main.c      (working copy)
> @@ -58,7 +58,7 @@
>  PROTOTYPE ((HyPortLibrary * portLibrary, int argc, char **argv, UDATA
> handle,
>             jint version, jboolean ignoreUnrecognized, char *mainClass,
>             UDATA classArg, char *propertiesFileName,
> -            int isStandaloneJar, char *vmdllsubdir));
> +            int isStandaloneJar, char *vmdllsubdir, int versionFlag));
>  static int createVMArgs
>  PROTOTYPE ((HyPortLibrary * portLibrary, int argc, char **argv,
>             jint version, jboolean ignoreUnrecognized,
> @@ -227,8 +227,9 @@
>                        /* The arg is a JAR file to run */
>                        isStandaloneJar = 1;
>                }
> -               if (0 == strcmp ("-version", argv[i])) {
> -            versionFlag = 1;
> +               if (0 == strncmp ("-version", argv[i], 8)) {
> +            /* Display version information */
> +            versionFlag = i;
>                }
>                if (0 == strcmp ("-showversion", argv[i])) {
>                        /* We are being asked to print our version and
> continue */
> @@ -363,12 +364,6 @@
>         }
>     }
>
> -  if (versionFlag == 1) {
> -    /*
> -     * We are being asked to print our version, and quit
> -     */
> -    hyfile_printf (PORTLIB, HYPORT_TTY_OUT, HY_COPYRIGHT_STRING "\n");
> -  }
>   /* set up the properties file */
>   propertiesFileName = hymem_allocate_memory (strlen (vmiPath) + 12);
>   if (propertiesFileName == NULL)
> @@ -392,7 +387,7 @@
>   /* main launcher processing in this function */
>   rc = invocation
>       (PORTLIB, argc, argv, handle, JNI_VERSION_1_4, JNI_TRUE, mainClass,
> -       classArg, propertiesFileName, isStandaloneJar, vmdllsubdir);
> +       classArg, propertiesFileName, isStandaloneJar, vmdllsubdir,
> versionFlag);
>   if (rc)
>     {
>          /* Print an error message except in the case where an uncaught
> Exception
> @@ -642,7 +637,7 @@
>  invocation (HyPortLibrary * portLibrary, int argc, char **argv, UDATA
> handle,
>             jint version, jboolean ignoreUnrecognized, char *mainClass,
>             UDATA classArg, char *propertiesFileName,
> -            int isStandaloneJar, char *vmdllsubdir)
> +            int isStandaloneJar, char *vmdllsubdir, int versionFlag)
>  {
>   JavaVMInitArgs vm_args;
>   JavaVM *jvm;
> @@ -678,6 +673,27 @@
>     }
>
>   rc = 0;
> +
> +  if (versionFlag) {
> +      jclass clazz;
> +      jmethodID mID;
> +      jstring jStrObject;
> +
> +      jStrObject = (*env)->NewStringUTF (env, argv[versionFlag]);
> +      if (!jStrObject) return 3;
> +
> +      clazz = (*env)->FindClass (env,
> "org/apache/harmony/luni/util/Version");
> +      if (!clazz) return 3;
> +
> +      mID = (*env)->GetStaticMethodID (env, clazz, "version",
> +                         "(Ljava/lang/String;)V");
> +      if (!mID) return 3;
> +
> +      (*env)->CallStaticVoidMethod(env, clazz, mID, jStrObject);
> +
> +      return 0;
> +  }
> +
>   if (mainClass)
>     {
>       if (isStandaloneJar)
> @@ -952,7 +968,8 @@
>    {
>        if ( (strcmp (argv[i], "-jar") != 0)
>            && (strncmp (argv[i], "-vmdir:", 7) != 0)
> -           && (strncmp (argv[i], "-vm:", 4) != 0) )
> +           && (strncmp (argv[i], "-vm:", 4) != 0)
> +           && (strncmp (argv[i], "-version", 8) != 0))
>        {
>           /* special coding for -classpath and -cp */
>           /* they get passed to the vm as -Djava.class.path */
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message