An obscure research project could accelerate innovation in language design
blog.plan99.net
blog.plan99.net
You can't solve that with JITs. From what I have seen, JITs are very useful for taking away the overhead of indirect calls and similar dynamic behaviour, but I don't think that's going to be the primary language design challenge of the future. No compiler can (usefully) extract significant amounts of parallelism from an algorithm which has none, and current programming models are not particularly convenient for expressing parallel algorithms. While current languages allow you to express parallelism by using low-level features, the resulting program will invariably be non-portable. High-level parallel languages (or maybe libraries) are the only solution I can see.
https://github.com/pcpratts/rootbeer1
http://openjdk.java.net/projects/sumatra/
There has been work done on automatically identifying and running ordinary JVM hotspots on the GPU.
That said, I agree that automatic parallelisation is a hard problem. I don't think it's the only interesting area of language innovation: most of the innovations making programmers lives easier in recent years have nothing to do with it.
Intel/AMD processors have complex branch predictors and instruction decoders and SIMD, ARM has conditional execution and some sort of quasi-SIMD, and GPUs have a weird hybrid of SIMD and multi-threaded-single-whatever (execution??) with sorta-kinda shared memory. Not only do these architectures implement memory access differently, the way basic control flow operations (conditionals and loops) work is physically different.
That's not even including architectures like SPARC or specialized DSPs. Or FPGAs, which are a whole different universe.
Imperative languages are probably hopeless, but declarative languages may work. Functional languages in its current popular incarnations is about as hard to compile intelligently as imperative code, but I think that functional array programming (where bulk operations are primitives) show promise. Consider computing the average of every row of an n*m matrix 'a' (a 2D array). In Haskell-ish syntax, we would write this as:
map (map (/m)) (map sum a)
Now the compiler really only has to figure out two high-level things: how to apply a function (division by 'm') to every element of an array, and how to sum equally-sized segments of an array. Summing is again an instance of a more primitive bulk operation, reduction, which is parallel in theory, and has known efficient parallel implementations on most hardware. It's also possible to do some fusion for this small example, but my point is that we will need a programming model where the individual statement or expression works at a much higher level, and has much stronger properties, than in most current languages. You still need to teach the compiler about each specific hardware platform you want to target, of course (possibly by automatic learning or autotuning, as in http://www.lift-project.org/ ).My hypothesis is that a common DSL framework would be just an ordinary programming language (e.g. an extended version of Haskell or Rust) that allows library writers to subset its AST and substitute a code generator for its preferred subset. That way, a DSL writer doesn't have to re implement expression parsing, type checking, error messages, ... but instead just has to do the code generation. Moreover, it would limit fragmentation since the DSLs are, by requirement, the same syntax as the host language, so users would have a more consistent experience between different languages instead of working across arbitrarily different syntaxes.
Whether these restricted languages are doable as embedded DSLs in general-purpose language remains to be seen. There have been attempts that work pretty well (Accelerate for Haskell is the one I know best), but they are limited in expressibility, and the ergonomics (type errors and conceptual clarity) are not great. Also, even with all the work that has gone into Accelerate, the end result is only useful to Haskell programmers, which is a shame. Perhaps this can be solved with a sufficient amount of shared infrastructure. Access to the real AST, instead of the lifted operations used by Accelerate, would be a good start.
Ziggurat[0] was an attempt at a general-purpose system to communicate static properties of DSLs past the more general host language (where they don't necessarily apply). It probably falls under the "ergonomics are not great" category though.
0: http://www.ccs.neu.edu/home/shivers/papers/ziggurat-jfp.pdf
I'd argue that the Racket language (or language platform, depending on your view of things) shows it's possible with its #lang mechanism and macro system. For example, though Racket proper is untyped, Typed Racket is implemented as a #lang with macros and includes an optimizing compiler that removes runtime checks on programs that typecheck successfully.
And it's true that the hard part is still transforming a representation close to the problem domain into a VM-executable one, as they are worlds apart. Then there is also an ecosystem problem, which forces us into the meta world and generating specific code in a specific format instead of doing anything with a VM. I didn't really see the appeal last time we discussed it and I don't see it now.
There are a lot of computational tasks that can not run on a smartphone today. It'd be great to run an IDE, a few baclground classification tasks, and a high quality augmented reality VR headset app on a device with an 8 hour battery under that load and fits in my pocket.
That's not happening without lots of hardware customization.
More relevant is power. The more wasted cycles the shorter your battery life. The hotter that device implanted in you becomes. The worse the cooling problem in the datacenter.
It's naive to think that "computers are fast enough".
A lot of VM design is at the expense of memory consumption over speed. Not just the JVM, but I think v8 memory usage got out of control recently and they had to go back to an interpreter in some cases.
VMs in the future should probably be optimized for power. More memory usage means more power usage. It matters both on mobile devices and in data centers.
The startup time issue is annoying as well. I like the general idea, but making startup time even worse than the JVM itself makes it unattractive.
The startup time issue is being solved with ah ahead-of-time Java compiler with whole-world analysis that we are developing. It runs hello-world in our Ruby implementation in about 100ms, which is an order of magnitude faster than the normal JVM.
I'm pretty sure the v8 changes were motivated by phones, so maybe there is room for another project like Graal and Truffle with a different set of constraints.
Also, for web services in particular (not sure if that is a major use case), I would question the view of making individual requests faster. I recall Steve Souders said he was a back end guy at Yahoo working on latency, and then he switched to front end performance because he found that the front end was eating up all the time.
In my experience this is too true. In other words, if you had a server where requests were taking 100 ms, and you made them take 50 ms through VM design, you would be a hero! But somehow front end engineers are still constructing pages with 10 - 30 full seconds of latency (especially on mobile) out of back end requests that take 100ms. There's just a lot more room to optimize there, whereas sometimes I feel like VMs are trying to squeeze blood out of a stone.
And I agree that there will be demand for such a "black box" approach, where you just take an arbitrary program and make it faster. But I'm interested in overall system performance, and in that case, a little bit of application knowledge can work wonders. One of my pet peeves is that often performance tools like time and space profilers are sort of an afterthought that programmers use only when they have problems. They write this huge spagehetti of allocation, and then 2 years later they start tuning the GC.
This is partly the fault of programmers and partly the fault of the language ecosystem. It would be nicer if the language exposed integrated tools. I dont' know that much about the JVM ecosystem, but they always feel like a "separate thing" you have to go research and choose and download and install. I think Go's tooling is a good example here.
Anyway, I think this is an interesting project. In particular I think the focus on polyglot programming is fantastic. I too feel the pain of enormous amounts of duplicated work -- e.g. even at say Google with a relatively small set of languages like C++, Java, and Python, there were still all these separate "worlds" and gradually engineers became sequestered in their own world. IMO Go made things worse and not better -- it was yet another native runtime that didn't even interoperate all that well with C++, let alone Java or Python!!!
Agree.
Do you know if this can generate native code without any JVM dependencies? For instance, could I implement a C compiler that outputs optimized native code just like gcc or clang?
At any rate, it sounds like this research could be used to produce the tools we want, even if this is not it. For instance, PHP could use a JIT, if it didn't cause slow warm-ups and blow up memory usage.
Yes it can! However you get a native VM that doesn't need the JVM for your language. You don't get a native executable for your application.
Pretty amazing claims being made here, but I do like the idea of it. Build up your language grammar, then get a compiler, debugger and runtime for basically free. Definitely will have to play around with this soon.
It works really well though; abstract the complexities of the AST through the use of various different methodologies so that designers can do what they do best, design. The shortcomings, I'd imagine, are the same with MPS in-so-much that the limitations imposed are defined by the system. And when you run into those boundaries, they are hard and unforgiving -- much like trying to use Python in a non-pythonic manner.
MPS is fascinating because it lets you create non-text based programming languages and have them actually interop with text based programming in a useful way.
Graal & Truffle are a product of Oracle Labs, the part of the Java team which does VM and compiler research.
[/quote]
So if a language using this becomes successful, Oracle will hit you with an intellectual property lawsuit?
Based on past behavior, Oracle intends Graal and Truffle to do the same.
Edit: Actually, I suspect the name Graal is a play on JVM-based Grails, which, along with Apache Groovy, has the same culture of drawing users in with false promises then charging them for OCI consulting and G2One conferences to manage the resulting technical debt. Perhaps Graal means Oracle ain't buying theirs, they're building their own.
The commercial features aren't relevant to most developers, so it's all a bit of a storm in a teacup. There's certainly no bait and switch.
The Google lawsuit was partly because they didn't use the actual Java source code so they didn't benefit from those open source licenses. But bear in mind:
• Google won, Oracle lost, multiple times. I'm guessing they won't try that again.
• Google has since switched to the OpenJDK source code, not away from it. They are now actually working more closely with Oracle, not less.
Weird I know, but that's how it's played out.
If you're smaller than Google, dealing with Oracle might be outside your budget. Safer not to.