News for hackers. Stuff that matters.
Re:The descent to C by mrtbld on Tuesday January 28, 2014 @06:02AM (#7136406)
> Java throws away its type information when compiling to byte code, and then the JIT reconstructs the types at runtime

Is it a fictive analogy or is it actually how the Java VM behaves?

Re:The descent to C by snuxoll on Tuesday January 28, 2014 @12:01PM (#7138173)
That's precisely how the JVM behave, which aggravates a lot of people when writing code using generics. In C# I can do the following:

    public T getInstance<T>() {
        return this.Instances[typeof(T)];
    }
Or, even better:

    public T createInstance<T>() {
        return new T();
    }
Meanwhile Java requires this:

    public <T> T getInstance(Class<T> cls) {
        return this.instances[cls];
    }
The type information above (the generic parameter T) is stripped after compilation, so the Class parameter is needed on the method to get a solid reference to the type we need to work with at run-time. This gets worse when we want to do the second example.

    public <T> T createInstance(Class<T> cls) {
        return cls.newInstance();
    }
It gets even more fun when you throw in non-default constructors. Non-reified generics are a giant pain in the butt.
Re:The descent to C by pkolaczk on Tuesday January 28, 2014 @02:00PM (#7138967)
There are cases when reified generics are a giant pain in the butt and non-reified ones are the right solution. See Scala or F# and .NET interoperability.
Re:The descent to C by chubot on Tuesday January 28, 2014 @12:35PM (#7138405)
It's definitely the case for generics, as someone pointed out.

If you look at the JVM byte code, you can see this has to be the case: http://en.wikipedia.org/wiki/Java_bytecode

Once you're in byte code, you don't have your static types anymore -- that is, types that are independent of control flow. You have types on individual instructions.

So basically you lost some type information before the JIT even sees it. Now, it doesn't actually matter for speed, as Mike Pall (LuaJIT author) would say. His point is that dynamically typed languages can be just as fast as statically typed languages, because you have more information at runtime.

Re:The descent to C by pkolaczk on Tuesday January 28, 2014 @07:56AM (#7136759)
I guess he meant JavaScript. JavaScript is dynamic and JS JITs try to reconstruct types at runtime to improve performance. Java is statically typed and, with a minor exception of generic type arguments, types are accessible both at compiletime and runtime.