[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 indirection which is \Nknown as a weak reference. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We have this hypothetical CacheClass \Nthat I've devised. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,At this point it is a weak reference. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Then we get it. This is calling the weak \Nreference routine. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Now it becomes a strong reference so \Nit's not going to be garbage collected. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,When we get to the return path it becomes \Na weak reference again Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,because our strong reference \Nhas disappeared. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The salient points in this example are: Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We're employing a method to get \Na reference. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We're checking an item to see if \Nit's null. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So let's say that the JVM decided to \Ngarbage collect this Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,before we executed the method. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The weak reference class is still valid \Nbecause we've got a strong reference to it Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,but the actual object behind this is gone. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If we're too late and the garbage \Ncollector has killed it Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,it will be null and we return. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So it's a level of indirection to see \Ndoes this still exist Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,if so can I please have it and then \Noperate on it as normal Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and then return becomes weak \Nreference again. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This example program is quite useful when\Nwe look at how it's implemented in the JVM Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and we'll go through a few things now. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,First off we'll go through the byte code. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The only point of this slide is to \Nshow it's roughly Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,the same as this. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We get our variable. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We use our getter. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This bit is extra this checkcast. \NThe reason that bit is extra is Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,because we're using the equivalent of \Na template in Java. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And the way that's implemented in Java is \Nit just basically casts everything to an Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,object so that requires extra \Ncompiler information. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And this is the extra check. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The rest of this we load the reference, \Nwe check to see if it is null, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If it's not null we invoke a virtual \Nfunction - is it the image? Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and we return as normal. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Essentially the point I'm trying to make \Nis when we compile this to byte code Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,this execution happens. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This null check happens. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This execution happens. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And we return. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,In the actual Java class files we've not \Nlost anything. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is what it looks like when it's \Nbeen JIT'd. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Now we've lost lots of things. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The JIT has done quite a few clever things\Nwhich I'll talk about. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,First off if we look down here there's \Na single branch here. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And this is only if our check cast failed Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If we've got comments on the \Nright hand side. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Our get method has been in-lined so \Nwe're no longer calling. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We seem to have lost our null check,\Nthat's just gone. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And again we've got a get field as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That's no longer a method, \Nthat's been in-lined as well Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We've also got some other cute things. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Those more familiar with AArch64 will \Nunderstand that the pointers we're using Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,are 32bit not 64bit. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,What we're doing is getting a pointer \Nand shifting it left 3 Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and widening it to a 64bit pointer. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We've also got 32bit pointers on a \N64bit system as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So that's saving a reasonable amount \Nof memory and cache. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,To summarise. We don't have any \Nbranches or function calls Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and we've got a lot of in-lining. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We did have function calls in the \Nclass file so it's the JVM Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,it's the JIT that has done this. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We've got no null checks either and I'm \Ngoing to talk through this now. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The null check elimination is quite a \Nclever feature in Java and other programs. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The idea behind null check elimination is Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,most of the time this object is not \Ngoing to be null. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If this object is null the operating \Nsystem knows this quite quickly. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So if you try to de-reference a null \Npointer you'll get either a SIGSEGV or Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,a SIGBUS depending on a \Nfew circumstances. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That goes straight back to the JVM Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and the JVM knows where the null \Nexception took place. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Because it knows where the exception took \Nplace it can look this up Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and unwind it as part of an exception. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Those null checks just go.\NCompletely gone. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Most of the time this works and you are \Nsaving a reasonable amount of execution. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I'll talk about when it doesn't work \Nin a second. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That's reasonably clever. We have similar \Nprogramming techniques in other places Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,even the Linux kernel for instance when \Nyou copy data to and from user space Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,it does pretty much identical the same \Nthing. It has an exception unwind table Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and it knows if it catches a page fault on\Nthis particular program counter Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,it can deal with it because it knows \Nthe program counter and it knows Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,conceptually what it was doing. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,In a similar way the JIT know what its \Ndoing to a reasonable degree. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It can handle the null check elimination. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I mentioned the sneaky one. We've got\Nessentially 32bit pointers Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,on a 64bit system. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Most of the time in Java people typically \Nspecify heap size smaller than 32GB. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Which is perfect if you want to use 32bit \Npointers and left shift 3. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Because that gives you 32GB of \Naddressable memory. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That's a significant memory saving because\Notherwise a lot of things would double up. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,There's a significant number of pointers \Nin Java. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The one that should make people \Njump out of their seat is Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,the fact that most methods in Java are \Nactually virtual. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So what the JVM has actually done is \Nin-lined a virtual function. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,A virtual function is essentially a \Nfunction were you don't know where Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,you're going until run time. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can have several different classes \Nand they share the same virtual function Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,in the base class and dependent upon \Nwhich specific class you're running Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,different virtual functions will \Nget executed. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,In C++ that will be a read from a V table\Nand then you know where to go. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The JVM's in-lined it. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We've saved a memory load. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We've saved a branch as well Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The reason the JVM can in-line it is \Nbecause the JVM knows Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,every single class that has been loaded. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So it knows that although this looks \Npolymorphic to the casual programmer Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It is actually monomorphic.\NThe JVM knows this. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Because it knows this it can be clever.\NAnd this is really clever. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That's a significant cost saving. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is all great. I've already mentioned \Nthe null check elimination. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We're taking a signal as most of you know \Nif we do that a lot it's going to be slow. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Jumping into kernel, into user, \Nbouncing around. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The JVM also has a notion of \N'OK I've been a bit too clever now; Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I need to back off a bit' Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Also there's nothing stopping the user \Nloading more classes Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and rendering the monomorphic \Nassumption invalid. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So the JVM needs to have a notion of \Nbackpeddling and go Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,'Ok I've gone to far and need to \Nde-optimise' Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The JVM has the ability to de-optimise. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,In other words essentially knows that for \Ncertain code paths everything's OK. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,But for certain new objects it can't get \Naway with these tricks. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,By the time the new objects are executed \Nthey are going to be safe. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,There are ramifications for this.\NThis is the important thing to consider Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,with something like Java and other \Nlanguages and other virtual machines. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If you're trying to profile this it means \Nthere is a very significant ramification. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can have the same class and \Nmethod JITd multiple ways Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and executed at the same time. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So if you're trying to find a hot spot \Nthe program counter's nodding off. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Because you can refer to the same thing \Nin several different ways. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is quite common as well as \Nde-optimisation does take place. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That's something to bear in mind with JVM \Nand similar runtime environments. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can get a notion of what the JVM's \Ntrying to do. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can ask it nicely and add a print \Ncompilation option and it will tell you Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,what it's doing. \NThis is reasonably verbose. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Typically what happens is the JVM gets \Nexcited JITing everything and optimising Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,everything then it settles down. \N Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Until you load something new \Nand it gets excited again. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,There's a lot of logs. This is mainly \Nuseful for de-bugging but Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,it gives you an appreciation that it's \Ndoing a lot of work. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can go even further with a log \Ncompilation option. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That produces a lot of XML and that is \Nuseful for people debugging the JVM as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It's quite handy to get an idea of \Nwhat's going on. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If that is not enough information you \Nalso have the ability to go even further. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is beyond the limit of my \Nunderstanding. I've gone into this little Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,bit just to show you what can be done. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You have release builds of Open JDK \Nand they have debug builds of Open JDK. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The release builds will by default turn \Noff a lot of the diagnostic options. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can switch them back on again. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,When you do you can also gain insight \Ninto the actual, it's colloquially Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,referred to as the C2 JIT, the compiler there. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can see, for instance, objects in \Ntimelines and visualize them Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,as they're being optimised at various \Nstages and various things. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So this is based on a masters thesis \Nby Thomas Würthinger. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is something you can play with as \Nwell and see how far the optimiser goes. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And it's also good for people hacking \Nwith the JVM. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I'll move onto some stuff we did. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Last year we were working on the \Nbig data. Relatively new architecture Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,ARM64, it's called AArch64 in Open JDK \Nland but ARM64 in Debian land. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We were a bit concerned because \Neverything's all shiny and new. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Has it been optimised correctly? \NAre there any obvious things Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,we need to optimise?\NAnd we're also interested because Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,everything was so shiny and new in \Nthe whole system. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Not just the JVM but the glibc and \Nthe kernel as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So how do we get a view of all of this? Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I gave a quick talk before at the Debian \Nmini-conf before last [2014] about perf Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,so decided we could try and do some \Nclever things with Linux perf Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and see if we could get some actual useful\Ndebugging information out. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We have the flame graphs that are quite \Nwell known. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We also have some previous work, Johannes \Nhad a special perf map agent that Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,could basically hook into perf and it \Nwould give you a nice way of running Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,perf-top for want of a better expression and viewing the top Java function names. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is really good work and it's really \Ngood for a particular use case Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,if you just want to do a snap shot once \Nand see in that snap shot Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,where the hotspots where. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,For a prolonged work load with all \Nthe functions being JITd multiple ways Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,with the optimisation going on and \Neverything moving around Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,it require a little bit more information \Nto be captured. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I decided to do a little bit of work on a \Nvery similar thing to perf-map-agent Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,but an agent that would capture it over \Na prolonged period of time. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Here's an example Flame graph, these are \Nall over the internet. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is the SHA1 computation example that \NI gave at the beginning. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,As expected the VM intrinsic SHA1 is the \Ntop one. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Not expected by me was this quite \Nsignificant chunk of CPU execution time. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And there was a significant amount of \Ntime being spent copying memory Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,from the mmapped memory region \Ninto a heap and then that was Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,passed to the crypto engine. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So we're doing a ton of memory copies for \Nno good reason. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That essentially highlighted an example. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That was an assumption I made about Java \Nto begin with which was if you do Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,the equivalent of mmap it should just \Nwork like mmap right? Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You should just be able to address the \Nmemory. That is not the case.\N Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If you've got a file mapping object and \Nyou try to address it it has to be copied Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,into safe heap memory first. And that is \Nwhat was slowing down the programs. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If that was elided you could make the SHA1 computation even quicker. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So that would be the logical target you would want to optimise. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I wanted to extend Johannes' work \Nwith something called a Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Java Virtual Machine Tools Interface \Nprofiling agent. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is part of the Java Virtual Machine \Nstandard as you can make a special library Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and then hook this into the JVM. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And the JVM can expose quite a few \Nthings to the library. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It exposes a reasonable amount of \Ninformation as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Perf as well has the ability to look \Nat map files natively. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If you are profiling JavaScript, or \Nsomething similar, I think the Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Google V8 JavaScript engine will write \Nout a special map file that says Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,these program counter addresses correspond\Nto these function names. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I decided to use that in a similar way to \Nwhat Johannes did for the extended Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,profiling agent but I also decided to \Ncapture some more information as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I decided to capture the dis-assembly \Nso when we run perf annotate Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,we can see the actual JVM byte code \Nin our annotation. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We can see how it was JITd when it was \NJITd. We can see where the hotspots where. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And that's good. But we can go even better. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We can run an annotated trace that \Ncontains the Java class, Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,the Java method and the byte code all in \None place at the same time. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,You can see everything from the JVM \Nat the same place. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This works reasonably well because the \Nperf interface is extremely extensible. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And again we can do entire \Nsystem optimisation. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The bits in red here are the Linux kernel. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Then we got into libraries. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And then we got into Java and more \Nlibraries as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So we can see everything from top to bottom in one fell swoop. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is just a quick slide showing the \Nmechanisms employed. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Essentially we have this agent which is \Na shared object file. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And this will spit out useful files here \Nin a standard way. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And the Linux perf basically just records \Nthe perf data dump file as normal. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We have 2 sets of recording going on and \Nto report it it's very easy to do Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,normal reporting with the PID map. \N Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,This is just out of the box, works with the \NGoogle V8 engine as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If you want to do very clever annotations \Nperf has the ability to have Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Python scripts passed to it. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,So you can craft quite a dodgy Python \Nscript and that can interface Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,with the perf annotation output. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,That's how I was able to get the extra \NJava information in the same annotation. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And this is really easy to do; it's quite \Neasy to knock the script up. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And again the only thing we do for this \Nprofiling is we hook in the profiling Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,agent which dumps out various things. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,We preserve the frame pointer because \Nthat makes things considerably easier Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,on winding. This will effect \Nperformance a little bit. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And again when we're reporting we just \Nhook in a Python script. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It's really easy to hook everything in \Nand get it working. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,At the moment we have a JVMTI agent. It's \Nactually on http://git.linaro.org now. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Since I gave this talk Google have \Nextended perf anyway so it will do Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,quite a lot of similar things out of the \Nbox anyway. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It's worth having a look at the \Nlatest perf. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,These techniques in this slide deck can be\Nused obviously in other JITs quite easily. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,The fact that perf is so easy to extend \Nwith scripts can be useful Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,for other things. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And Open JDK has a significant amount of \Ncleverness associated with it that Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I thought was very surprising and good. \NSo that's what I covered on the talk. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,These are basically references to things \Nlike command line arguments Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,and the Flame graphs and stuff like that. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,If anyone is interested in playing with \NOpen JDK on ARM64 I'd suggest going here: Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,http://openjdk.linaro.org\NWhere the most recent builds are. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Obviously fixes are going in upstream and \Nthey're going into distributions as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,They're included in Open JDK so it should be good as well. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I've run through quite a few fundamental \Nthings reasonably quickly. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,I'd be happy to accept any questions \Nor comments Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And if you want to talk to me privately \Nabout Java afterwards feel free to Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,when no-ones looking. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,[Audience] Applause Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,[Audience] It's not really a question so \Nmuch as a comment. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Last mini-Deb conf we had a talk about \Nusing the JVM with other languages. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,And it seems to me that all this would \Napply even if you hate Java programming Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,language and want to write in, I don't \Nknow, lisp or something instead if you've Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,got a lisp system that can generate \NJVM byte code. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Yeah, totally. And the other \Nbig data language we looked at was Scala. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,It uses the JVM back end but a completely \Ndifferent language on the front. Dialogue: 0,9:59:59.99,9:59:59.99,Default,,0000,0000,0000,,Cheers guys.