[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Onto the second talk Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Steve Capper is going to tell us\Nabout the good bits of Java Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,They do exist Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,[Audience] Could this have been a \Nlightening talk? [Audience laughter] Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Believe it or not we've got some \Ngood stuff here. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I was as skeptical as you guys \Nwhen I first looked. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,First apologies for not attending this\Nmini-conf last year Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I was unfortunately ill on the day \NI was due to give this talk. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Let me figure out how to use a computer. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Sorry about this. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,There we go; it's because \NI've not woken up. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Last year I worked at Linaro in the \NEnterprise group and we performed analysis Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,on 'Big Data' applications sets. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,As many of you know quite a lot of these \Nbig data applications are written in Java. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I'm from ARM and we were very interested\Nin 64bit ARM support. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So this is mainly AArch64 examples \Nfor things like assembler Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,but most of the messages are \Npertinent for any architecture. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,These good bits are shared between \Nmost if not all the architectures. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Whilst trying to optimise a lot of \Nthese big data applications Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I stumbled a across quite a few things in \Nthe JVM and I thought Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,'actually that's really clever; \Nthat's really cool' Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So I thought that would make a good \Nbasis for a talk. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This talk is essentially some of the \Nclever things I found in the Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Java Virtual Machine; these \Noptimisations are in Open JDK. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Source is available it's all there, \Nreadily available and in play now. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I'm going to finish with some of the \Noptimisation work we did with Java. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,People who know me will know \NI'm not a Java zealot. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I don't particularly believe in \Nprogramming in a language over another one Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So to make it clear from the outset \NI'm not attempting to convert Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,anyone to Java programmers. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I'm just going to highlight a few salient \Nthings in the Java Virtual Machine Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,which I found to be quite clever and \Ninteresting Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and I'll try and talk through them \Nwith my understanding of them. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Let's jump straight in and let's \Nstart with an example. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is a minimal example for \Ncomputing a SHA1 sum of a file. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I've alluded some of the checking in the \Nbeginning of the function see when Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,command line parsing and that sort of \Nthing. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I've highlighted the salient points in red. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Essentially we instantiate a SHA1 \Ncrypto message service digest. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And we do the equivalent in \NJava of an mmap. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Get it all in memory. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And then we just put this status straight \Ninto the crypto engine. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And eventually at the end of the \Nprogram we'll spit out the SHA1 hash. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It's a very simple programme Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It's basically mmap, SHA1 output \Nthe hash afterwards. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,In order to concentrate on the CPU \Naspect rather than worry about IO Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I decided to cheat a little by \Nsetting this up. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I decided to use a sparse file. As many of\Nyou know a sparse file is a file that not Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,all the contents are necessarily stored \Non disc. The assumption is that the bits Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,that aren't stored are zero. For instance\Non Linux you can create a 20TB sparse file Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,on a 10MB file system and use it as \Nnormal. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Just don't write too much to it otherwise \Nyou're going to run out of space. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The idea behind using a sparse file is I'm\Njust focusing on the computational aspects Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,of the SHA1 sum. I'm not worried about \Nthe file system or anything like that. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I don't want to worry about the IO. I \Njust want to focus on the actual compute. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,In order to set up a sparse file I used \Nthe following runes. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The important point is that you seek\Nand the other important point Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,is you set a count otherwise you'll fill your disc up. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I decided to run this against firstly \Nlet's get the native SHA1 sum command Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,that's built into Linux and let's normalise these results and say that's 1.0. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I used an older version of the Open \NJDK and ran the Java programme Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and that's 1.09 times slower than the \Nreference command. That's quite good. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Then I used the new Open JDK, this is now\Nthe current JDK as this is a year on. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And 0.21 taken. It's significantly faster. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I've stressed that I've done nothing \Nsurreptitious in the Java program. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It is mmap, compute, spit result out. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,But the Open JDK has essentially got \Nsome more context information. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I'll talk about that as we go through. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Before when I started Java I had a very \Nsimplistic view of Java. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Traditionally Java is taught as a virtual \Nmachine that runs byte code. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Now when you compile a Java program it \Ncompiles into byte code. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The older versions of the Java Virtual \NMachine would interpret this byte code Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and then run through. Newer versions would\Nemploy a just-in-time engine and try and Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,compile this byte code into native machine code. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That is not the only thing that goes on\Nwhen you run a Java program. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,There is some extra optimisations as well.\NSo this alone would not account for Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,the newer version of the SHA1 \Nsum beingsignificantly faster Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,than the distro supply one. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Java knows about context. It has a class \Nlibrary and these class libraries Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,have reasonably well defined purposes. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We have classes that provide \Ncrypto services. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We have some misc unsafe that every \Nsingle project seems to pull in their Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,project when they're not supposed to. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,These have well defined meanings. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,These do not necessarily have to be \Nwritten in Java. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,They come as Java classes, \Nthey come supplied. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,But most JVMs now have a notion \Nof a virtual machine intrinsic Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And the virtual machine intrinsic says ok \Nplease do a SHA1 in the best possible way Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,that your implementation allows. This is \Nsomething done automatically by the JVM. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You don't ask for it. If the JVM knows\Nwhat it's running on and it's reasonably Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,recent this will just happen \Nfor you for free. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And there's quite a few classes \Nthat do this. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,There's quite a few clever things with \Natomics, there's crypto, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,there's mathematical routines as well. \NMost of these routines in the Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,class library have a well defined notion \Nof a virtual machine intrinsic Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and they do run reasonably optimally. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,They are a subject of continuous \Noptimisation as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We've got some runes that are \Npresented on the slides here. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,These are quite useful if you \Nare interested in Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,how these intrinsics are made. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can ask the JVM to print out a lot of\Nthe just-in-time compiled code. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can ask the JVM to print out the \Nnative methods as well as these intrinsics Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and in this particular case after sifting \Nthrough about 5MB of text Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I've come across this particular SHA1 sum\Nimplementation. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is AArch64. This is employing the \Ncryptographic extensions Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,in the architecture. So it's essentially \Nusing the CPU instructions which Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,would explain why it's faster. But again \Nit's done all this automatically. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This did not require any specific runes \Nor anything to activate. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We'll see a bit later on how you can \Nmore easily find the hot spots Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,rather than sifting through a lot \Nof assembler. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I've mentioned that the cryptographic \Nengine is employed and again Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,this routine was generated at run \Ntime as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is one of the important things about \Ncertain execution of amps like Java. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You don't have to know everything at \Ncompile time. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You know a lot more information at \Nrun time and you can use that Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,in theory to optimise. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can switch off these clever routines. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,For instance I've got a deactivate \Nhere and we get back to the Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,slower performance we expected. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Again, this particular set of routines is \Npresent in Open JDK, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I think for all the architectures that support it. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We get this optimisation for free on X86 \Nand others as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It works quite well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That was one surprise I came across \Nas the instrinsics. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,One thing I thought it would be quite \Ngood to do would be to go through Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,a slightly more complicated example. \NAnd use this example to explain Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,a lot of other things that happen \Nin the JVM as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I will spend a bit of time going through \Nthis example Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and explain roughly the notion of what \Nit's supposed to be doing. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is an imaginary method that I've \Ncontrived to demonstrate lot of points Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,in the fewest possible lines of code. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I'll start with what it's meant to do. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is meant to be a routine that gets a\Nreference to something and let's you know Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,whether or not it's an image and in a \Nhypothetical cache. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I'll start with the important thing \Nhere the weak reference. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,In Java and other garbage collected \Nlanguages we have the notion of references. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Most of the time when you are running a \NJava program you have something like a Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,variable name and that is in the current \Nexecution context that is referred to as a Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,strong reference to the object. In other \Nwords I can see it. I am using it. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Please don't get rid of it. \NBad things will happen if you do. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So the garbage collector knows \Nnot to get rid of it. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,In Java and other languages you also \Nhave the notion of a weak reference. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is essentially the programmer saying\Nto the virtual machine Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,"Look I kinda care about this but \Njust a little bit." Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,"If you want to get rid of it feel free \Nto but please let me know." Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is why this is for a cache class. \NFor instance the JVM in this particular Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,case could decide that it's running quite \Nlow on memory this particular xMB image Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,has not been used for a while it can \Ngarbage collect it. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The important thing is how we go about \Nexpressing this in the language. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We can't just have a reference to the \Nobject because that's a strong reference Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and the JVM will know it can't get \Nrid of this because the program Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,can see it actively. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So we have a level of direction which is known as