News for hackers. Stuff that matters.
Re:Vulnerability in Microsoft TLS library could allow remote... by Someone1234 on Tuesday November 11, 2014 @04:23PM (#8592262)
At runtime modern Java is around 10x slower than modern C++ (assuming both are fully optimised and the benchmark is relatively unbiased).

That isn't significant on modern hardware relative to other bottlenecks (network, IO, etc). Plus people keep adding additional security layers between C/C++ and the CPU which eat away at some of its advantages (e.g. Docker containers, virtual machines, exploit detection libraries, etc).

Java speed matters in certain situations and for certain tasks. For example I wouldn't rewrite an SQL database into Java since performance could definitely be impactful there. But realistically CPU times are such a tiny minority of latency that it stopped being relevant a very long time ago.

Re:Vulnerability in Microsoft TLS library could allow remote... by mike_hearn on Tuesday November 11, 2014 @04:38PM (#8592361)
At runtime modern Java is around 10x slower than modern C++ (assuming both are fully optimised and the benchmark is relatively unbiased).

I don't think you can pick a single number like that, it depends very much on what the code is doing.

You probably got this 10x figure from a Google paper published a few years ago (https://days2011.scala-lang.org/sites/days2011/files/ws3-1-H...). Redux: the default out of the box 32 bit JVM (in 2011) was 12x slower than the same algorithm implemented in Java. But with a few simple GC flag changes, it became 3.7x slower. And then the Java version had a few further simple optimisations applied to the code and it became as fast as the original C++ version.

Meanwhile the C++ version was optimised again and became around 3x to 5x faster, but that version relied heavily on Google proprietary data structure code and could not be open sourced (!). So for most programmers on most projects, it seems likely to be a wash.

Meanwhile an alternative benchmark that reimplemented a non-trivial C++ program in Java found it became 1.09 to 1.5 times slower, but that was with Java 6 which is now two generations out of date:

http://www.best-of-robotics.org/pages/publications/gherardi1...

It would be interesting to get more recent benchmarks with the latest JVMs and C++ compilers.

Re:Vulnerability in Microsoft TLS library could allow remote... by TheLoneWolfling on Tuesday November 11, 2014 @10:50PM (#8593918)
As you say, it depends very much on what the code is doing.

In particular, anything requiring manipulating unsigned values all over the place will be a lot slower.

Also, see this[1] for talk about JGit. An actual project with direct comparisons.

[1] http://marc.info/?l=git&m=124111702609723

Re:Vulnerability in Microsoft TLS library could allow remote... by pjmlp on Wednesday November 12, 2014 @03:13AM (#8594481)
Those comparisons will be again out of date when Java 9+ comes out with value types, official unsafe package and lots of other goodies for performance being worked on.
Re:Vulnerability in Microsoft TLS library could allow remote... by mike_hearn on Wednesday November 12, 2014 @06:06AM (#8594871)
I'm not aware of any intent on adding unsigned types in Java 9 though. The lack of them is a real PITA, for sure. Not only for performance but it's incredibly easy to forget a & 0xFF here or there and introduce bugs.

The MMAP thing is also a good point. I believe HotSpot will compile the get methods on the MappedByteBuffer down to raw access so it shouldn't matter much for performance, in theory, but the code is still damned ugly. I never understood why they can't expose it as a byte[].

Re:Vulnerability in Microsoft TLS library could allow remote... by pjmlp on Wednesday November 12, 2014 @07:22AM (#8595083)
> I'm not aware of any intent on adding unsigned types in Java 9 though.

You kind of have them in Java 8, but not as primitive type.

https://blogs.oracle.com/darcy/entry/unsigned_api

I also think a very least having ubyte would be quite nice.

Apparently the reason behind the decision has to do with overflows and underflows in unsigned arithmetic.

Hotspot is just one of many Java native compilers out there , so it is better not to rely on what Hotspot does.

On the other hand, you can make use of JIT Watch or Solaris Studio debugging to see what Assembly is being generated.

> I never understood why they can't expose it as a byte[].

Maybe the official unsafe class will make this better.

Re:Vulnerability in Microsoft TLS library could allow remote... by 0x0 on Tuesday November 11, 2014 @04:39PM (#8592365)
Do you have a source for that 10x number?

I don't understand why a just-in-time java compiler would produce slower code than an ahead-of-time c++ compiler, especially since the java compiler has much more information available (exact cpu revision, cache and ram sizes, and hot spot profiling).

Re:Vulnerability in Microsoft TLS library could allow remote... by mike_hearn on Tuesday November 11, 2014 @04:45PM (#8592411)
Java has certain qualities that make it sometimes harder to optimise, which is one reason it relies so heavily on profile guided optimisation. For example, it's very vulnerable to GC stalls if escape analysis can't identify all your variables as eligible for stack allocation. Escape analysis is complex and a little fragile, from what I've heard (I never tested it myself).
Re:Vulnerability in Microsoft TLS library could allow remote... by pjmlp on Wednesday November 12, 2014 @03:16AM (#8594487)
> Escape analysis is complex and a little fragile, from what I've heard (I never tested it myself).

Depends which JVM you are talking about.

For example Graal is more aggressive than Hotspot in selecting variables for escape analysis.

Each JVM (IBM, HP, Aonix, ...) has different quality levels in escape analysis.

Re:Vulnerability in Microsoft TLS library could allow remote... by afsina on Tuesday November 11, 2014 @05:46PM (#8592765)
That is totally wrong. I dealt with a lot of code from numerical computing to general data structures and I have never seen C++ code runs 10x faster than current JVMs. Heck not even with SIMD. From what I see for actual applications what you get is at best x1.5 speed up and a lot of agony on the C++ part.
Re:Vulnerability in Microsoft TLS library could allow remote... by throwawayaway on Tuesday November 11, 2014 @07:43PM (#8593298)
time ./hello

one in c++, one in java

10x is giving it too much credit.

Re:Vulnerability in Microsoft TLS library could allow remote... by pluies_public on Tuesday November 11, 2014 @07:52PM (#8593339)
That example will be horribly skewed by the JVM startup time, which is a known problem, but doesn't affect your program once it's started. It's pretty meaningless to compare programs that short, eg. scripts because noone sane would write them in either C++ or Java.
Re:Vulnerability in Microsoft TLS library could allow remote... by throwawayaway on Wednesday November 12, 2014 @05:19AM (#8594741)
If you were to reimplement Unix in Java: what would happen to the paradigm of small utilities that do one job well, that you combine into something greater than the sum of its parts? I think you'll find a lot of short programs are written in C++.

Java wouldn't work very well!

Re:Vulnerability in Microsoft TLS library could allow remote... by mike_hearn on Wednesday November 12, 2014 @06:10AM (#8594886)
Um, if you reimplemented UNIX in Java you'd probably do a much better job than the UNIX creators were able to do.

In particular, running a program from bash would simply classload it into the existing VM, not invoke a whole separate VM, and then it'd be more or less instant, except you'd have the potential for much more flexible APIs and combinations of tools. Look at PowerShell for an example.

Re:Vulnerability in Microsoft TLS library could allow remote... by throwawayaway on Wednesday November 12, 2014 @06:39AM (#8594957)
I don't have the technical chops to disagree with you. But rest assured I would not do a better job. Last time I checked java programs do not like operating within the same VM[0]. Last time I looked at it, it was to get a bunch of people running Eclipse remotely from the same JVM instance on a huge box in 2012 or something. It was a no-goer, but some experimental JVM's claimed to support it. [1]

Powershell is a terrible example for the performance point I am trying to make, whatever about its flexibility.

[0] http://www.javalobby.org/java/forums/t72620.html

[0] http://stackoverflow.com/a/13496610

[1]http://www.ibm.com/developerworks/library/j-multitenant-java... (this now looks less experimental but I'm willing to bet >1 instance of eclipse, or bash for that matter would not work very well).

I'm not sure how this works: http://www.excelsiorjet.com/

but it might help to alleviate the problem even though it still has a jvm.

https://en.wikipedia.org/wiki/Java_Classloader

looking at what you mention now, can a program classload itself? seems not: A class with a given name can only be loaded once by a given classloader.

Re:Vulnerability in Microsoft TLS library could allow remote... by mike_hearn on Wednesday November 12, 2014 @08:14AM (#8595276)
In practice big GUI apps like Eclipse are not intended to share a single VM with lots of other things, let alone multiple instances of itself. If people wanted to write tools that did that (i.e. if it was common) then they could, but it's not enforced. For example even if at the Java level you can separate stuff out, native code to handle the GUI framework might not be expecting it.
Re:Vulnerability in Microsoft TLS library could allow remote... by throwawayaway on Wednesday November 12, 2014 @09:00AM (#8595412)
I know they weren't written to do so obviously but you can see how it's a related example. You can also understand why if it was the sort of thing that could work it would be worthwhile, what with the amount of RAM each of the Eclipse users had devoted to its (in theory duplicated per user) JVM.

I doubt you would even have to go as far as native extensions for GUI before you start running into problems even though the programs are written in managed code.

Can you better explain how in practice Java programs could share a VM in replacing a typical Unix bash environment/userland?

Would they have to use the special IBM JVM? Would bash have to contain grep as a class? e.g.

machine:~$ grep include Source | grep -v 32 | grep -v 16

Reading about "JAR hell" I really don't think it would work very well.

Interestingly in the IBM link provided earlier they load up substantial non GUI servers such as Tomcat, Jetty and JRuby and achieve a startup time that is twice as fast.

They also have hello world:

Hello World Print "HelloWorld" and then sleep

Multi-tenant JVM: 309

Hand-tuned: 73

Default: 63

Improvement with multitenant: 4.2X to 4.9X

Even with this I think a C++ version would eat it for breakfast. It would be interesting to find out what would happen if a Single JVM were loaded on boot, all programs were loaded into that and compare the JVM based Unix on those terms with e.g. Solaris or something.

Re:Vulnerability in Microsoft TLS library could allow remote... by tshtf on Tuesday November 11, 2014 @04:38PM (#8592359)
[Citation required]
Re:Vulnerability in Microsoft TLS library could allow remote... by Someone1234 on Tuesday November 11, 2014 @05:24PM (#8592648)
mike_hearn beat me to it. See his post for a citation (and some other numbers).
Re:Vulnerability in Microsoft TLS library could allow remote... by afsina on Tuesday November 11, 2014 @05:49PM (#8592784)
And you stood corrected.