harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "daizi sheng" <daizish...@gmail.com>
Subject Re: [drlvm][jitrino] Problem on the implementation of Method_Table class
Date Mon, 12 Nov 2007 03:11:58 GMT
my example helloworld class may be misleading because it contains too deep
recursion.
to make the problem clear, just replace it with very very simple class

package helloworld;
public class Main {
    public static void main(String[] args) {
    }
}

this is ok because the parameters is load and processed simply before
running of the real program, I think

2007/11/12, daizi sheng <daizisheng@gmail.com>:
>
> the file is: working_vm\vm\jitrino\src\shared\methodtable.cpp
>
> in the implementation of member function *init*, there are some errors
>
> 1. parameter default_envvar is declared as a *const char* pointer, but
> used as normal pointer, here is the code snippet
>
> void Method_Table::init(const char *default_envvar, const char
> *envvarname)
> {
> ...
>     char *envvar = (char*)default_envvar;
> ...
>     if (envvar[0] == '"')
>         envvar ++;
>     if (envvar[strlen(envvar)-1] == '"')
>         envvar[strlen(envvar)-1] = '\0';
> ...
>
> the problem is that default_envvar is changed into a normal char pointer
> and then may be modified by the last statement.
> the source of this parameter is from the ctor of this class
>
> Method_Table::Method_Table(MemoryManager& memManager,
>                            const char *default_envvar,
>                            const char *envvarname,
>                            bool accept_by_default):
>
> 2. another problem of the above code snippet is that it does not check the
> boundary of the string in the last two statements
>
> image that if envvar contains only one character "\"", the double quote
> character, in the last *if* statement,
> strlen(envvar) will be 0, and strlen(envvar)-1 will be 0xffffffff (for
> 32-bit pointer) because strlen() return unsigned value normally
>
> the following steps is about how to trigger out this error
>
> 1). add the following line in the opt.emconf (just under -XX:
> jit.CS_OPT.arg.optimizer.inline.pipeline=CS_OPT_inliner_pipeline)
> -XX:jit.CS_OPT.arg.optimizer.inline.skip_methods="
>
> 2). prepare a helloworld like this
> package helloworld;
> public class Main {
>     public static int fun()
>     {
>         fun();
>         return 1;
>     }
>     public static void main(String[] args) {
>         fun();
>     }
>
> }
>
> 3). run java.exe like this
> working_vm\build\deploy\jdk\jre\bin\java.exe
> -Xem:working_vm\vm\jitrino\config\ia32\opt.emconf  -jar helloworld.jar
>
> 4). at least on my machine, the vm launcher will crash, here is the desc.
> of my machine
>
> windows xp professional version 2002 SP2
> Pentium(R) 4CPU 3.00Ghz
> 2.99Ghz, 0.99GB of RAM
>
> 3. solution for such errors is simple, maybe simple code refactor
>
>

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