[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:01.70,0:00:03.48,Default,,0000,0000,0000,,Onto the second talk of the day. Dialogue: 0,0:00:10.56,0:00:14.45,Default,,0000,0000,0000,,Steve Capper is going to tell us\Nabout the good bits of Java Dialogue: 0,0:00:15.10,0:00:17.20,Default,,0000,0000,0000,,They do exist Dialogue: 0,0:00:17.20,0:00:21.07,Default,,0000,0000,0000,,[Audience] Could this have been a \Nlightening talk? [Audience laughter] Dialogue: 0,0:00:23.26,0:00:26.02,Default,,0000,0000,0000,,Believe it or not we've got some \Ngood stuff here. Dialogue: 0,0:00:27.32,0:00:30.46,Default,,0000,0000,0000,,I was as skeptical as you guys \Nwhen I first looked. Dialogue: 0,0:00:30.53,0:00:34.76,Default,,0000,0000,0000,,First many apologies for not attending \Nthe mini-conf last year Dialogue: 0,0:00:34.76,0:00:40.03,Default,,0000,0000,0000,,I was unfortunately ill on the day \NI was due to give this talk. Dialogue: 0,0:00:43.66,0:00:45.59,Default,,0000,0000,0000,,Let me figure out how to use a computer. Dialogue: 0,0:01:00.100,0:01:03.02,Default,,0000,0000,0000,,Sorry about this. Dialogue: 0,0:01:12.61,0:01:15.57,Default,,0000,0000,0000,,There we go; it's because \NI've not woken up. Dialogue: 0,0:01:19.95,0:01:26.94,Default,,0000,0000,0000,,Last year I worked at Linaro in the \NEnterprise group and we performed analysis Dialogue: 0,0:01:28.01,0:01:31.86,Default,,0000,0000,0000,,on so called 'Big Data' application sets. Dialogue: 0,0:01:32.21,0:01:37.42,Default,,0000,0000,0000,,As many of you know quite a lot of these \Nbig data applications are written in Java. Dialogue: 0,0:01:38.46,0:01:42.55,Default,,0000,0000,0000,,I'm from ARM and we were very interested\Nin 64bit ARM support. Dialogue: 0,0:01:42.93,0:01:47.26,Default,,0000,0000,0000,,So this is mainly AArch64 examples \Nfor things like assembler Dialogue: 0,0:01:47.68,0:01:52.68,Default,,0000,0000,0000,,but most of the messages are \Npertinent for any architecture. Dialogue: 0,0:01:53.50,0:01:58.22,Default,,0000,0000,0000,,These good bits are shared between \Nmost if not all the architectures. Dialogue: 0,0:01:58.96,0:02:02.78,Default,,0000,0000,0000,,Whilst trying to optimise a lot of \Nthese big data applications Dialogue: 0,0:02:03.03,0:02:06.41,Default,,0000,0000,0000,,I stumbled a across quite a few things in \Nthe JVM and I thought Dialogue: 0,0:02:06.41,0:02:11.48,Default,,0000,0000,0000,,'actually that's really clever; \Nthat's really cool' Dialogue: 0,0:02:12.61,0:02:16.66,Default,,0000,0000,0000,,So I thought that would make a good \Nbasis for an interesting talk. Dialogue: 0,0:02:16.67,0:02:20.31,Default,,0000,0000,0000,,This talk is essentially some of the \Nclever things I found in the Dialogue: 0,0:02:20.33,0:02:25.32,Default,,0000,0000,0000,,Java Virtual Machine; these \Noptimisations are in OpenJDK. Dialogue: 0,0:02:26.24,0:02:31.60,Default,,0000,0000,0000,,Source is available it's all there, \Nreadily available and in play now. Dialogue: 0,0:02:32.99,0:02:37.51,Default,,0000,0000,0000,,I'm going to finish with some of the \Noptimisation work we did with Java. Dialogue: 0,0:02:38.37,0:02:42.57,Default,,0000,0000,0000,,People who know me will know \NI'm not a Java zealot. Dialogue: 0,0:02:42.57,0:02:47.86,Default,,0000,0000,0000,,I don't particularly believe in \Nprogramming in a language over another one Dialogue: 0,0:02:48.44,0:02:51.37,Default,,0000,0000,0000,,So to make it clear from the outset \NI'm not attempting to convert Dialogue: 0,0:02:51.37,0:02:53.62,Default,,0000,0000,0000,,anyone to Java programmers. Dialogue: 0,0:02:53.62,0:02:57.22,Default,,0000,0000,0000,,I'm just going to highlight a few salient \Nthings in the Java Virtual Machine Dialogue: 0,0:02:57.22,0:02:59.57,Default,,0000,0000,0000,,which I found to be quite clever and \Ninteresting Dialogue: 0,0:02:59.58,0:03:03.83,Default,,0000,0000,0000,,and I'll try and talk through them \Nwith my understanding of them. Dialogue: 0,0:03:04.35,0:03:08.87,Default,,0000,0000,0000,,Let's jump straight in and let's \Nstart with an example. Dialogue: 0,0:03:10.06,0:03:14.50,Default,,0000,0000,0000,,This is a minimal example for \Ncomputing a SHA1 sum of a file. Dialogue: 0,0:03:15.21,0:03:19.72,Default,,0000,0000,0000,,I've omitted some of the checking in the \Nbeginning of the function see when Dialogue: 0,0:03:19.72,0:03:22.20,Default,,0000,0000,0000,,command line parsing and that sort of \Nthing. Dialogue: 0,0:03:22.20,0:03:25.04,Default,,0000,0000,0000,,I've highlighted the salient \Npoints in red. Dialogue: 0,0:03:25.04,0:03:29.65,Default,,0000,0000,0000,,Essentially we instantiate a SHA1 \Ncrypto message service digest. Dialogue: 0,0:03:30.12,0:03:35.42,Default,,0000,0000,0000,,And we do the equivalent in \NJava of an mmap. Dialogue: 0,0:03:35.91,0:03:37.99,Default,,0000,0000,0000,,Get it all in memory. Dialogue: 0,0:03:37.99,0:03:42.39,Default,,0000,0000,0000,,And then we just put this status straight \Ninto the crypto engine. Dialogue: 0,0:03:42.49,0:03:46.63,Default,,0000,0000,0000,,And eventually at the end of the \Nprogram we'll spit out the SHA1 hash. Dialogue: 0,0:03:46.63,0:03:48.68,Default,,0000,0000,0000,,It's a very simple program. Dialogue: 0,0:03:48.68,0:03:53.47,Default,,0000,0000,0000,,It's basically mmap, SHA1, output \Nthe hash afterwards. Dialogue: 0,0:03:55.86,0:04:02.83,Default,,0000,0000,0000,,In order to concentrate on the CPU \Naspect rather than worry about IO Dialogue: 0,0:04:03.82,0:04:07.43,Default,,0000,0000,0000,,I decided to cheat a little bit by \Nsetting this up. Dialogue: 0,0:04:08.13,0:04:14.66,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,0:04:14.66,0:04:19.53,Default,,0000,0000,0000,,all the contents are stored necessarily \Non disc. The assumption is that the bits Dialogue: 0,0:04:19.53,0:04:26.38,Default,,0000,0000,0000,,that aren't stored are zero. For instance\Non Linux you can create a 20TB sparse file Dialogue: 0,0:04:26.38,0:04:30.80,Default,,0000,0000,0000,,on a 10MB file system and use it as \Nnormal. Dialogue: 0,0:04:30.80,0:04:34.40,Default,,0000,0000,0000,,Just don't write too much to it otherwise \Nyou're going to run out of space. Dialogue: 0,0:04:34.40,0:04:40.68,Default,,0000,0000,0000,,The idea behind using a sparse file is I'm\Njust focusing on the computational aspects Dialogue: 0,0:04:40.68,0:04:44.73,Default,,0000,0000,0000,,of the SHA1 sum. I'm not worried about \Nthe file system or anything like that. Dialogue: 0,0:04:44.73,0:04:48.91,Default,,0000,0000,0000,,I don't want to worry about the IO. I \Njust want to focus on the actual compute. Dialogue: 0,0:04:48.91,0:04:52.86,Default,,0000,0000,0000,,In order to set up a sparse file I used \Nthe following runes. Dialogue: 0,0:04:52.86,0:04:56.73,Default,,0000,0000,0000,,The important point is that you seek\Nand the other important point Dialogue: 0,0:04:56.73,0:05:01.05,Default,,0000,0000,0000,,is you set a count otherwise you'll \Nfill your disc up. Dialogue: 0,0:05:02.56,0:05:09.22,Default,,0000,0000,0000,,I decided to run this against firstly \Nlet's get the native SHA1 sum command Dialogue: 0,0:05:09.22,0:05:15.19,Default,,0000,0000,0000,,that's built into Linux and let's \Nnormalise these results and say that's 1.0 Dialogue: 0,0:05:17.47,0:05:21.45,Default,,0000,0000,0000,,I used an older version of the OpenJDK \Nand ran the Java program Dialogue: 0,0:05:21.45,0:05:28.50,Default,,0000,0000,0000,,and that's 1.09 times slower than the \Nreference command. That's quite good. Dialogue: 0,0:05:30.01,0:05:38.94,Default,,0000,0000,0000,,Then I used the new OpenJDK, this is now\Nthe current JDK as this is a year on. Dialogue: 0,0:05:38.94,0:05:44.66,Default,,0000,0000,0000,,And 0.21 taken. It's significantly faster. Dialogue: 0,0:05:45.71,0:05:50.69,Default,,0000,0000,0000,,I've stressed that I've done nothing \Nsurreptitious in the Java program. Dialogue: 0,0:05:50.69,0:05:54.48,Default,,0000,0000,0000,,It is mmap, compute, spit result out. Dialogue: 0,0:05:55.77,0:06:00.84,Default,,0000,0000,0000,,But the OpenJDK has essentially got \Nsome more context information. Dialogue: 0,0:06:00.84,0:06:03.62,Default,,0000,0000,0000,,I'll talk about that as we go through. Dialogue: 0,0:06:06.20,0:06:11.01,Default,,0000,0000,0000,,Before when I started Java I had a very \Nsimplistic view of Java. Dialogue: 0,0:06:11.01,0:06:16.82,Default,,0000,0000,0000,,Traditionally Java is taught as a virtual \Nmachine that runs bytecode. Dialogue: 0,0:06:16.82,0:06:21.42,Default,,0000,0000,0000,,Now when you compile a Java program it \Ncompiles into bytecode. Dialogue: 0,0:06:21.42,0:06:25.43,Default,,0000,0000,0000,,The older versions of the Java Virtual \NMachine would interpret this bytecode Dialogue: 0,0:06:25.43,0:06:31.94,Default,,0000,0000,0000,,and then run through. Newer versions \Nwould employ a just-in-time engine Dialogue: 0,0:06:32.44,0:06:38.17,Default,,0000,0000,0000,,and try and compile this bytecode \Ninto native machine code. Dialogue: 0,0:06:39.33,0:06:42.84,Default,,0000,0000,0000,,That is not the only thing that goes on\Nwhen you run a Java program. Dialogue: 0,0:06:42.84,0:06:47.32,Default,,0000,0000,0000,,There is some extra optimisations as well.\NSo this alone would not account for Dialogue: 0,0:06:47.32,0:06:51.98,Default,,0000,0000,0000,,the newer version of the SHA1 \Nsum being significantly faster Dialogue: 0,0:06:51.98,0:06:55.57,Default,,0000,0000,0000,,than the distro supplied one. Dialogue: 0,0:06:55.57,0:07:00.70,Default,,0000,0000,0000,,Java knows about context. It has a class \Nlibrary and these class libraries Dialogue: 0,0:07:00.70,0:07:04.18,Default,,0000,0000,0000,,have reasonably well defined purposes. Dialogue: 0,0:07:04.18,0:07:07.60,Default,,0000,0000,0000,,We have classes that provide \Ncrypto services. Dialogue: 0,0:07:07.60,0:07:10.95,Default,,0000,0000,0000,,We have some misc unsafe that every \Nsingle project seems to pull in their Dialogue: 0,0:07:10.95,0:07:13.49,Default,,0000,0000,0000,,project when they're not supposed to. Dialogue: 0,0:07:13.49,0:07:17.30,Default,,0000,0000,0000,,These have well defined meanings. Dialogue: 0,0:07:17.30,0:07:20.78,Default,,0000,0000,0000,,These do not necessarily have to be \Nwritten in Java. Dialogue: 0,0:07:20.78,0:07:24.29,Default,,0000,0000,0000,,They come as Java classes, \Nthey come supplied. Dialogue: 0,0:07:24.29,0:07:28.59,Default,,0000,0000,0000,,But most JVMs now have a notion \Nof a virtual machine intrinsic. Dialogue: 0,0:07:28.59,0:07:34.79,Default,,0000,0000,0000,,And the virtual machine intrinsic says ok \Nplease do a SHA1 in the best possible way Dialogue: 0,0:07:34.79,0:07:39.17,Default,,0000,0000,0000,,that your implementation allows. This is \Nsomething done automatically by the JVM. Dialogue: 0,0:07:39.17,0:07:43.48,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,0:07:43.48,0:07:47.56,Default,,0000,0000,0000,,recent this will just happen \Nfor you for free. Dialogue: 0,0:07:47.56,0:07:50.05,Default,,0000,0000,0000,,And there's quite a few classes \Nthat do this. Dialogue: 0,0:07:50.05,0:07:53.52,Default,,0000,0000,0000,,There's quite a few clever things with \Natomics, there's crypto, Dialogue: 0,0:07:53.52,0:07:58.21,Default,,0000,0000,0000,,there's mathematical routines as well. \NMost of these routines in the Dialogue: 0,0:07:58.21,0:08:02.88,Default,,0000,0000,0000,,class library have a well defined notion \Nof a virtual machine intrinsic Dialogue: 0,0:08:02.88,0:08:06.99,Default,,0000,0000,0000,,and they do run reasonably optimally. Dialogue: 0,0:08:06.99,0:08:11.04,Default,,0000,0000,0000,,They are a subject of continuous \Noptimisation as well. Dialogue: 0,0:08:11.68,0:08:15.95,Default,,0000,0000,0000,,We've got some runes that are \Npresented on the slides here. Dialogue: 0,0:08:17.10,0:08:21.34,Default,,0000,0000,0000,,These are quite useful if you \Nare interested in Dialogue: 0,0:08:21.34,0:08:24.33,Default,,0000,0000,0000,,how these intrinsics are made. Dialogue: 0,0:08:24.33,0:08:28.80,Default,,0000,0000,0000,,You can ask the JVM to print out a lot of\Nthe just-in-time compiled code. Dialogue: 0,0:08:28.80,0:08:34.90,Default,,0000,0000,0000,,You can ask the JVM to print out the \Nnative methods as well as these intrinsics Dialogue: 0,0:08:34.90,0:08:40.37,Default,,0000,0000,0000,,and in this particular case after sifting \Nthrough about 5MB of text Dialogue: 0,0:08:40.37,0:08:45.04,Default,,0000,0000,0000,,I've come across this particular SHA1 sum\Nimplementation. Dialogue: 0,0:08:45.04,0:08:52.48,Default,,0000,0000,0000,,This is AArch64. This is employing the \Ncryptographic extensions Dialogue: 0,0:08:52.48,0:08:54.09,Default,,0000,0000,0000,,in the architecture. Dialogue: 0,0:08:54.09,0:08:57.33,Default,,0000,0000,0000,,So it's essentially using the CPU \Ninstructions which would explain why Dialogue: 0,0:08:57.33,0:09:00.46,Default,,0000,0000,0000,,it's faster. But again it's done \Nall this automatically. Dialogue: 0,0:09:00.46,0:09:05.95,Default,,0000,0000,0000,,This did not require any specific runes \Nor anything to activate. Dialogue: 0,0:09:07.62,0:09:12.01,Default,,0000,0000,0000,,We'll see a bit later on how you can \Nmore easily find the hot spots Dialogue: 0,0:09:12.01,0:09:14.78,Default,,0000,0000,0000,,rather than sifting through a lot \Nof assembler. Dialogue: 0,0:09:14.78,0:09:18.66,Default,,0000,0000,0000,,I've mentioned that the cryptographic \Nengine is employed and again Dialogue: 0,0:09:18.66,0:09:23.09,Default,,0000,0000,0000,,this routine was generated at run \Ntime as well. Dialogue: 0,0:09:23.09,0:09:28.07,Default,,0000,0000,0000,,This is one of the important things about \Ncertain execution of amps like Java. Dialogue: 0,0:09:28.07,0:09:31.44,Default,,0000,0000,0000,,You don't have to know everything at \Ncompile time. Dialogue: 0,0:09:31.44,0:09:35.02,Default,,0000,0000,0000,,You know a lot more information at \Nrun time and you can use that Dialogue: 0,0:09:35.02,0:09:37.41,Default,,0000,0000,0000,,in theory to optimise. Dialogue: 0,0:09:37.41,0:09:40.01,Default,,0000,0000,0000,,You can switch off these clever routines. Dialogue: 0,0:09:40.01,0:09:43.18,Default,,0000,0000,0000,,For instance I've got a deactivate \Nhere and we get back to the Dialogue: 0,0:09:43.18,0:09:46.70,Default,,0000,0000,0000,,slower performance we expected. Dialogue: 0,0:09:46.70,0:09:52.97,Default,,0000,0000,0000,,Again, this particular set of routines is \Npresent in OpenJDK, Dialogue: 0,0:09:52.97,0:09:57.00,Default,,0000,0000,0000,,I think for all the architectures that \Nsupport it. Dialogue: 0,0:09:57.00,0:10:00.76,Default,,0000,0000,0000,,We get this optimisation for free on X86 \Nand others as well. Dialogue: 0,0:10:00.76,0:10:03.07,Default,,0000,0000,0000,,It works quite well. Dialogue: 0,0:10:03.07,0:10:07.91,Default,,0000,0000,0000,,That was one surprise I came across \Nas the instrinsics. Dialogue: 0,0:10:07.91,0:10:13.10,Default,,0000,0000,0000,,One thing I thought it would be quite \Ngood to do would be to go through Dialogue: 0,0:10:13.10,0:10:17.87,Default,,0000,0000,0000,,a slightly more complicated example. \NAnd use this example to explain Dialogue: 0,0:10:17.87,0:10:21.50,Default,,0000,0000,0000,,a lot of other things that happen \Nin the JVM as well. Dialogue: 0,0:10:21.50,0:10:24.39,Default,,0000,0000,0000,,I will spend a bit of time going through \Nthis example Dialogue: 0,0:10:24.39,0:10:29.77,Default,,0000,0000,0000,,and explain roughly the notion of what \Nit's supposed to be doing. Dialogue: 0,0:10:32.53,0:10:39.30,Default,,0000,0000,0000,,This is an imaginary method that I've \Ncontrived to demonstrate a lot of points Dialogue: 0,0:10:39.30,0:10:42.76,Default,,0000,0000,0000,,in the fewest possible lines of code. Dialogue: 0,0:10:42.76,0:10:45.24,Default,,0000,0000,0000,,I'll start with what it's meant to do. Dialogue: 0,0:10:45.24,0:10:50.61,Default,,0000,0000,0000,,This is meant to be a routine that gets a\Nreference to something and let's you know Dialogue: 0,0:10:50.61,0:10:55.95,Default,,0000,0000,0000,,whether or not it's an image and in a \Nhypothetical cache. Dialogue: 0,0:10:58.16,0:11:02.25,Default,,0000,0000,0000,,I'll start with the important thing \Nhere the weak reference. Dialogue: 0,0:11:02.25,0:11:09.02,Default,,0000,0000,0000,,In Java and other garbage collected \Nlanguages we have the notion of references Dialogue: 0,0:11:09.02,0:11:13.43,Default,,0000,0000,0000,,Most of the time when you are running a \NJava program you have something like a Dialogue: 0,0:11:13.43,0:11:19.35,Default,,0000,0000,0000,,variable name and that is in the current \Nexecution context that is referred to as a Dialogue: 0,0:11:19.35,0:11:24.18,Default,,0000,0000,0000,,strong reference to the object. In other \Nwords I can see it. I am using it. Dialogue: 0,0:11:24.18,0:11:27.29,Default,,0000,0000,0000,,Please don't get rid of it. \NBad things will happen if you do. Dialogue: 0,0:11:27.29,0:11:30.56,Default,,0000,0000,0000,,So the garbage collector knows \Nnot to get rid of it. Dialogue: 0,0:11:30.56,0:11:35.77,Default,,0000,0000,0000,,In Java and other languages you also \Nhave the notion of a weak reference. Dialogue: 0,0:11:35.77,0:11:40.04,Default,,0000,0000,0000,,This is essentially the programmer saying\Nto the virtual machine Dialogue: 0,0:11:40.04,0:11:43.94,Default,,0000,0000,0000,,"Look I kinda care about this but \Njust a little bit." Dialogue: 0,0:11:44.22,0:11:49.05,Default,,0000,0000,0000,,"If you want to get rid of it feel free \Nto but please let me know." Dialogue: 0,0:11:49.49,0:11:53.95,Default,,0000,0000,0000,,This is why this is for a CacheClass. \NFor instance the JVM in this particular Dialogue: 0,0:11:53.95,0:12:01.20,Default,,0000,0000,0000,,case could decide that it's running quite \Nlow on memory this particular xMB image Dialogue: 0,0:12:01.20,0:12:04.42,Default,,0000,0000,0000,,has not been used for a while it can \Ngarbage collect it. Dialogue: 0,0:12:04.42,0:12:08.53,Default,,0000,0000,0000,,The important thing is how we go about \Nexpressing this in the language. Dialogue: 0,0:12:08.53,0:12:12.98,Default,,0000,0000,0000,,We can't just have a reference to the \Nobject because that's a strong reference Dialogue: 0,0:12:12.98,0:12:17.63,Default,,0000,0000,0000,,and the JVM will know it can't get \Nrid of this because the program Dialogue: 0,0:12:17.63,0:12:19.34,Default,,0000,0000,0000,,can see it actively. Dialogue: 0,0:12:19.34,0:12:23.71,Default,,0000,0000,0000,,So we have a level of indirection which \Nis known as a weak reference. Dialogue: 0,0:12:24.65,0:12:28.62,Default,,0000,0000,0000,,We have this hypothetical CacheClass \Nthat I've devised. Dialogue: 0,0:12:28.62,0:12:32.13,Default,,0000,0000,0000,,At this point it is a weak reference. Dialogue: 0,0:12:32.13,0:12:35.97,Default,,0000,0000,0000,,Then we get it. This is calling the weak \Nreference routine. Dialogue: 0,0:12:35.97,0:12:40.76,Default,,0000,0000,0000,,Now it becomes a strong reference so \Nit's not going to be garbage collected. Dialogue: 0,0:12:40.76,0:12:44.72,Default,,0000,0000,0000,,When we get to the return path it becomes \Na weak reference again Dialogue: 0,0:12:44.72,0:12:48.44,Default,,0000,0000,0000,,because our strong reference \Nhas disappeared. Dialogue: 0,0:12:48.44,0:12:50.86,Default,,0000,0000,0000,,The salient points in this example are: Dialogue: 0,0:12:50.86,0:12:54.29,Default,,0000,0000,0000,,We're employing a method to get \Na reference. Dialogue: 0,0:12:54.29,0:12:56.76,Default,,0000,0000,0000,,We're checking an item to see if \Nit's null. Dialogue: 0,0:12:56.76,0:13:01.05,Default,,0000,0000,0000,,So let's say that the JVM decided to \Ngarbage collect this Dialogue: 0,0:13:01.97,0:13:04.35,Default,,0000,0000,0000,,before we executed the method. Dialogue: 0,0:13:04.35,0:13:08.72,Default,,0000,0000,0000,,The weak reference class is still valid \Nbecause we've got a strong reference to it Dialogue: 0,0:13:08.72,0:13:11.79,Default,,0000,0000,0000,,but the actual object behind this is gone. Dialogue: 0,0:13:11.79,0:13:14.97,Default,,0000,0000,0000,,If we're too late and the garbage \Ncollector has killed it Dialogue: 0,0:13:14.97,0:13:17.79,Default,,0000,0000,0000,,it will be null and we return. Dialogue: 0,0:13:17.79,0:13:22.13,Default,,0000,0000,0000,,So it's a level of indirection to see \Ndoes this still exist Dialogue: 0,0:13:22.13,0:13:27.68,Default,,0000,0000,0000,,if so can I please have it and then \Noperate on it as normal Dialogue: 0,0:13:27.68,0:13:31.25,Default,,0000,0000,0000,,and then return becomes weak \Nreference again. Dialogue: 0,0:13:31.25,0:13:37.44,Default,,0000,0000,0000,,This example program is quite useful when\Nwe look at how it's implemented in the JVM Dialogue: 0,0:13:37.44,0:13:40.21,Default,,0000,0000,0000,,and we'll go through a few things now. Dialogue: 0,0:13:40.21,0:13:43.50,Default,,0000,0000,0000,,First off we'll go through the bytecode. Dialogue: 0,0:13:43.50,0:13:48.86,Default,,0000,0000,0000,,The only point of this slide is to \Nshow it's roughly Dialogue: 0,0:13:48.86,0:13:53.88,Default,,0000,0000,0000,,the same as this. Dialogue: 0,0:13:53.88,0:13:56.37,Default,,0000,0000,0000,,We get our variable. Dialogue: 0,0:13:56.37,0:13:58.82,Default,,0000,0000,0000,,We use our getter. Dialogue: 0,0:13:58.82,0:14:03.78,Default,,0000,0000,0000,,This bit is extra this checkcast. \NThe reason that bit is extra is Dialogue: 0,0:14:03.78,0:14:14.95,Default,,0000,0000,0000,,because we're using the equivalent of \Na template in Java. Dialogue: 0,0:14:14.95,0:14:18.98,Default,,0000,0000,0000,,And the way that's implemented in Java is \Nit just basically casts everything to an Dialogue: 0,0:14:18.98,0:14:23.34,Default,,0000,0000,0000,,object so that requires extra \Ncompiler information. Dialogue: 0,0:14:23.34,0:14:25.38,Default,,0000,0000,0000,,And this is the extra check. Dialogue: 0,0:14:25.38,0:14:30.80,Default,,0000,0000,0000,,The rest of this we load the reference, \Nwe check to see if it is null, Dialogue: 0,0:14:30.80,0:14:35.15,Default,,0000,0000,0000,,If it's not null we invoke a virtual \Nfunction - is it the image? Dialogue: 0,0:14:35.15,0:14:37.83,Default,,0000,0000,0000,,and we return as normal. Dialogue: 0,0:14:37.83,0:14:43.36,Default,,0000,0000,0000,,Essentially the point I'm trying to make \Nis when we compile this to bytecode Dialogue: 0,0:14:43.36,0:14:45.26,Default,,0000,0000,0000,,this execution happens. Dialogue: 0,0:14:45.26,0:14:46.76,Default,,0000,0000,0000,,This null check happens. Dialogue: 0,0:14:46.76,0:14:48.36,Default,,0000,0000,0000,,This execution happens. Dialogue: 0,0:14:48.36,0:14:50.00,Default,,0000,0000,0000,,And we return. Dialogue: 0,0:14:50.00,0:14:54.61,Default,,0000,0000,0000,,In the actual Java class files we've not \Nlost anything. Dialogue: 0,0:14:54.85,0:14:58.17,Default,,0000,0000,0000,,This is what it looks like when it's \Nbeen JIT'd. Dialogue: 0,0:14:58.17,0:15:01.11,Default,,0000,0000,0000,,Now we've lost lots of things. Dialogue: 0,0:15:01.11,0:15:05.58,Default,,0000,0000,0000,,The JIT has done quite a few clever things\Nwhich I'll talk about. Dialogue: 0,0:15:05.58,0:15:10.64,Default,,0000,0000,0000,,First off if we look down here there's \Na single branch here. Dialogue: 0,0:15:10.64,0:15:15.08,Default,,0000,0000,0000,,And this is only if our check cast failed Dialogue: 0,0:15:17.04,0:15:19.99,Default,,0000,0000,0000,,We've got comments on the \Nright hand side. Dialogue: 0,0:15:19.99,0:15:25.52,Default,,0000,0000,0000,,Our get method has been inlined so \Nwe're no longer calling. Dialogue: 0,0:15:27.01,0:15:31.36,Default,,0000,0000,0000,,We seem to have lost our null check,\Nthat's just gone. Dialogue: 0,0:15:32.18,0:15:35.60,Default,,0000,0000,0000,,And again we've got a get field as well. Dialogue: 0,0:15:35.60,0:15:39.80,Default,,0000,0000,0000,,That's no longer a method, \Nthat's been inlined as well. Dialogue: 0,0:15:39.80,0:15:42.32,Default,,0000,0000,0000,,We've also got some other cute things. Dialogue: 0,0:15:42.32,0:15:45.74,Default,,0000,0000,0000,,Those more familiar with AArch64 \Nwill understand Dialogue: 0,0:15:45.74,0:15:49.59,Default,,0000,0000,0000,,that the pointers we're using \Nare 32bit not 64bit. Dialogue: 0,0:15:49.59,0:15:53.80,Default,,0000,0000,0000,,What we're doing is getting a pointer \Nand shifting it left 3 Dialogue: 0,0:15:53.80,0:15:56.83,Default,,0000,0000,0000,,and widening it to a 64bit pointer. Dialogue: 0,0:15:56.100,0:16:01.66,Default,,0000,0000,0000,,We've also got 32bit pointers on a \N64bit system as well. Dialogue: 0,0:16:02.04,0:16:05.99,Default,,0000,0000,0000,,So that's saving a reasonable amount \Nof memory and cache. Dialogue: 0,0:16:05.99,0:16:09.58,Default,,0000,0000,0000,,To summarise. We don't have any \Nbranches or function calls Dialogue: 0,0:16:09.58,0:16:12.63,Default,,0000,0000,0000,,and we've got a lot of inlining. Dialogue: 0,0:16:12.63,0:16:15.91,Default,,0000,0000,0000,,We did have function calls in the \Nclass file so it's the JVM; Dialogue: 0,0:16:15.91,0:16:18.24,Default,,0000,0000,0000,,it's the JIT that has done this. Dialogue: 0,0:16:18.24,0:16:22.33,Default,,0000,0000,0000,,We've got no null checks either and I'm \Ngoing to talk through this now. Dialogue: 0,0:16:24.07,0:16:29.43,Default,,0000,0000,0000,,The null check elimination is quite a \Nclever feature in Java and other programs. Dialogue: 0,0:16:30.45,0:16:33.34,Default,,0000,0000,0000,,The idea behind null check elimination is Dialogue: 0,0:16:33.34,0:16:37.49,Default,,0000,0000,0000,,most of the time this object is not \Ngoing to be null. Dialogue: 0,0:16:37.72,0:16:42.75,Default,,0000,0000,0000,,If this object is null the operating \Nsystem knows this quite quickly. Dialogue: 0,0:16:43.18,0:16:47.79,Default,,0000,0000,0000,,So if you try to dereference a null \Npointer you'll get either a SIGSEGV or Dialogue: 0,0:16:47.79,0:16:50.92,Default,,0000,0000,0000,,a SIGBUS depending on a \Nfew circumstances. Dialogue: 0,0:16:50.92,0:16:53.46,Default,,0000,0000,0000,,That goes straight back to the JVM Dialogue: 0,0:16:53.46,0:16:57.97,Default,,0000,0000,0000,,and the JVM knows where the null \Nexception took place. Dialogue: 0,0:16:58.47,0:17:01.76,Default,,0000,0000,0000,,Because it knows where it took \Nplace it can look this up Dialogue: 0,0:17:01.76,0:17:05.36,Default,,0000,0000,0000,,and unwind it as part of an exception. Dialogue: 0,0:17:05.36,0:17:09.71,Default,,0000,0000,0000,,Those null checks just go.\NCompletely gone. Dialogue: 0,0:17:09.71,0:17:15.45,Default,,0000,0000,0000,,Most of the time this works and you are \Nsaving a reasonable amount of execution. Dialogue: 0,0:17:16.42,0:17:19.84,Default,,0000,0000,0000,,I'll talk about when it doesn't work \Nin a second. Dialogue: 0,0:17:19.84,0:17:23.91,Default,,0000,0000,0000,,That's reasonably clever. We have similar \Nprogramming techniques in other places Dialogue: 0,0:17:23.91,0:17:27.68,Default,,0000,0000,0000,,even the Linux kernel for instance when \Nyou copy data to and from user space Dialogue: 0,0:17:27.68,0:17:30.91,Default,,0000,0000,0000,,it does pretty much identical \Nthe same thing. Dialogue: 0,0:17:30.91,0:17:36.46,Default,,0000,0000,0000,,It has an exception unwind table and it \Nknows if it catches a page fault on Dialogue: 0,0:17:36.46,0:17:40.13,Default,,0000,0000,0000,,this particular program counter\Nit can deal with it because it knows Dialogue: 0,0:17:40.13,0:17:43.73,Default,,0000,0000,0000,,the program counter and it knows\Nconceptually what it was doing. Dialogue: 0,0:17:43.73,0:17:47.63,Default,,0000,0000,0000,,In a similar way the JIT knows what its \Ndoing to a reasonable degree. Dialogue: 0,0:17:47.63,0:17:51.87,Default,,0000,0000,0000,,It can handle the null check elimination. Dialogue: 0,0:17:53.06,0:17:57.32,Default,,0000,0000,0000,,I mentioned the sneaky one. We've got\Nessentially 32bit pointers Dialogue: 0,0:17:57.32,0:17:59.48,Default,,0000,0000,0000,,on a 64bit system. Dialogue: 0,0:17:59.48,0:18:04.53,Default,,0000,0000,0000,,Most of the time in Java people typically \Nspecify heap size smaller than 32GB. Dialogue: 0,0:18:05.40,0:18:10.00,Default,,0000,0000,0000,,Which is perfect if you want to use 32bit \Npointers and left shift 3. Dialogue: 0,0:18:10.00,0:18:12.80,Default,,0000,0000,0000,,Because that gives you 32GB of \Naddressable memory. Dialogue: 0,0:18:12.80,0:18:18.84,Default,,0000,0000,0000,,That's a significant memory saving because\Notherwise a lot of things would double up. Dialogue: 0,0:18:18.85,0:18:22.86,Default,,0000,0000,0000,,There's a significant number of pointers \Nin Java. Dialogue: 0,0:18:22.86,0:18:28.84,Default,,0000,0000,0000,,The one that should make people \Njump out of their seat is Dialogue: 0,0:18:28.84,0:18:32.22,Default,,0000,0000,0000,,the fact that most methods in Java are \Nactually virtual. Dialogue: 0,0:18:32.22,0:18:36.92,Default,,0000,0000,0000,,So what the JVM has actually done is \Ninlined a virtual function. Dialogue: 0,0:18:36.92,0:18:41.58,Default,,0000,0000,0000,,A virtual function is essentially a \Nfunction were you don't know where Dialogue: 0,0:18:41.58,0:18:43.37,Default,,0000,0000,0000,,you're going until run time. Dialogue: 0,0:18:43.37,0:18:47.33,Default,,0000,0000,0000,,You can have several different classes \Nand they share the same virtual function Dialogue: 0,0:18:47.33,0:18:51.44,Default,,0000,0000,0000,,in the base class and dependent upon \Nwhich specific class you're running Dialogue: 0,0:18:51.44,0:18:54.20,Default,,0000,0000,0000,,different virtual functions will \Nget executed. Dialogue: 0,0:18:54.20,0:18:59.52,Default,,0000,0000,0000,,In C++ that will be a read from a V table\Nand then you know where to go. Dialogue: 0,0:19:01.05,0:19:03.32,Default,,0000,0000,0000,,The JVM's inlined it. Dialogue: 0,0:19:03.32,0:19:05.10,Default,,0000,0000,0000,,We've saved a memory load. Dialogue: 0,0:19:05.10,0:19:07.92,Default,,0000,0000,0000,,We've saved a branch as well Dialogue: 0,0:19:07.92,0:19:11.80,Default,,0000,0000,0000,,The reason the JVM can inline it is \Nbecause the JVM knows Dialogue: 0,0:19:11.80,0:19:14.28,Default,,0000,0000,0000,,every single class that has been loaded. Dialogue: 0,0:19:14.28,0:19:19.52,Default,,0000,0000,0000,,So it knows that although this looks \Npolymorphic to the casual programmer Dialogue: 0,0:19:19.52,0:19:26.01,Default,,0000,0000,0000,,It actually is monomorphic.\NThe JVM knows this. Dialogue: 0,0:19:26.01,0:19:30.98,Default,,0000,0000,0000,,Because it knows this it can be clever.\NAnd this is really clever. Dialogue: 0,0:19:30.98,0:19:34.94,Default,,0000,0000,0000,,That's a significant cost saving. Dialogue: 0,0:19:35.24,0:19:40.55,Default,,0000,0000,0000,,This is all great. I've already mentioned \Nthe null check elimination. Dialogue: 0,0:19:41.36,0:19:46.95,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,0:19:46.95,0:19:51.14,Default,,0000,0000,0000,,Jumping into kernel, into user, \Nbouncing around. Dialogue: 0,0:19:51.14,0:19:55.52,Default,,0000,0000,0000,,The JVM also has a notion of \N'OK I've been a bit too clever now; Dialogue: 0,0:19:55.52,0:19:57.81,Default,,0000,0000,0000,,I need to back off a bit' Dialogue: 0,0:19:57.81,0:20:02.38,Default,,0000,0000,0000,,Also there's nothing stopping the user \Nloading more classes Dialogue: 0,0:20:02.38,0:20:06.80,Default,,0000,0000,0000,,and rendering the monomorphic \Nassumption invalid. Dialogue: 0,0:20:06.80,0:20:09.94,Default,,0000,0000,0000,,So the JVM needs to have a notion of \Nbackpeddling and go Dialogue: 0,0:20:09.94,0:20:14.10,Default,,0000,0000,0000,,'Ok I've gone to far and need to \Ndeoptimise' Dialogue: 0,0:20:14.10,0:20:16.88,Default,,0000,0000,0000,,The JVM has the ability to deoptimise. Dialogue: 0,0:20:16.88,0:20:22.60,Default,,0000,0000,0000,,In other words it essentially knows that \Nfor certain code paths everything's OK. Dialogue: 0,0:20:22.60,0:20:26.87,Default,,0000,0000,0000,,But for certain new objects it can't get \Naway with these tricks. Dialogue: 0,0:20:26.87,0:20:32.15,Default,,0000,0000,0000,,By the time the new objects are executed \Nthey are going to be safe. Dialogue: 0,0:20:32.27,0:20:35.36,Default,,0000,0000,0000,,There are ramifications for this.\NThis is the important thing to consider Dialogue: 0,0:20:35.36,0:20:39.82,Default,,0000,0000,0000,,with something like Java and other \Nlanguages and other virtual machines. Dialogue: 0,0:20:39.82,0:20:45.55,Default,,0000,0000,0000,,If you're trying to profile this it means \Nthere is a very significant ramification. Dialogue: 0,0:20:46.18,0:20:51.47,Default,,0000,0000,0000,,You can have the same class and \Nmethod JIT'd multiple ways Dialogue: 0,0:20:52.05,0:20:54.83,Default,,0000,0000,0000,,and executed at the same time. Dialogue: 0,0:20:54.83,0:20:59.95,Default,,0000,0000,0000,,So if you're trying to find a hot spot \Nthe program counter's nodding off. Dialogue: 0,0:21:00.58,0:21:03.62,Default,,0000,0000,0000,,Because you can refer to the same thing \Nin several different ways. Dialogue: 0,0:21:03.62,0:21:07.91,Default,,0000,0000,0000,,This is quite common as well as \Ndeoptimisation does take place. Dialogue: 0,0:21:08.94,0:21:13.72,Default,,0000,0000,0000,,That's something to bear in mind with JVM \Nand similar runtime environments. Dialogue: 0,0:21:15.84,0:21:18.98,Default,,0000,0000,0000,,You can get a notion of what the JVM's \Ntrying to do. Dialogue: 0,0:21:18.98,0:21:22.26,Default,,0000,0000,0000,,You can ask it nicely and add a print \Ncompilation option Dialogue: 0,0:21:22.26,0:21:24.67,Default,,0000,0000,0000,,and it will tell you what it's doing. Dialogue: 0,0:21:24.67,0:21:26.76,Default,,0000,0000,0000,,This is reasonably verbose. Dialogue: 0,0:21:26.76,0:21:29.72,Default,,0000,0000,0000,,Typically what happens is the JVM gets \Nexcited JIT'ing everything Dialogue: 0,0:21:29.72,0:21:32.41,Default,,0000,0000,0000,,and optimising everything then \Nit settles down. Dialogue: 0,0:21:32.41,0:21:35.15,Default,,0000,0000,0000,,Until you load something new \Nand it gets excited again. Dialogue: 0,0:21:35.15,0:21:38.28,Default,,0000,0000,0000,,There's a lot of logs. This is mainly \Nuseful for debugging but Dialogue: 0,0:21:38.28,0:21:42.12,Default,,0000,0000,0000,,it gives you an appreciation that it's \Ndoing a lot of work. Dialogue: 0,0:21:42.12,0:21:45.28,Default,,0000,0000,0000,,You can go even further with a log \Ncompilation option. Dialogue: 0,0:21:45.28,0:21:50.49,Default,,0000,0000,0000,,That produces a lot of XML and that is \Nuseful for people debugging the JVM as well. Dialogue: 0,0:21:51.18,0:21:54.43,Default,,0000,0000,0000,,It's quite handy to get an idea of \Nwhat's going on. Dialogue: 0,0:21:56.81,0:22:03.14,Default,,0000,0000,0000,,If that is not enough information you \Nalso have the ability to go even further. Dialogue: 0,0:22:04.74,0:22:07.33,Default,,0000,0000,0000,,This is beyond the limit of my \Nunderstanding. Dialogue: 0,0:22:07.33,0:22:10.94,Default,,0000,0000,0000,,I've gone into this little bit just to \Nshow you what can be done. Dialogue: 0,0:22:11.30,0:22:17.34,Default,,0000,0000,0000,,You have release builds of OpenJDK \Nand they have debug builds of OpenJDK. Dialogue: 0,0:22:17.34,0:22:23.74,Default,,0000,0000,0000,,The release builds will by default turn \Noff a lot of the diagnostic options. Dialogue: 0,0:22:24.64,0:22:27.66,Default,,0000,0000,0000,,You can switch them back on again. Dialogue: 0,0:22:27.66,0:22:33.30,Default,,0000,0000,0000,,When you do you can also gain insight \Ninto the actual, it's colloquially Dialogue: 0,0:22:33.30,0:22:37.34,Default,,0000,0000,0000,,referred to as the C2 JIT, \Nthe compiler there. Dialogue: 0,0:22:37.34,0:22:41.71,Default,,0000,0000,0000,,You can see, for instance, objects in \Ntimelines and visualize them Dialogue: 0,0:22:41.71,0:22:45.49,Default,,0000,0000,0000,,as they're being optimised at various \Nstages and various things. Dialogue: 0,0:22:45.49,0:22:51.98,Default,,0000,0000,0000,,So this is based on a masters thesis \Nby Thomas Würthinger. Dialogue: 0,0:22:53.58,0:22:58.45,Default,,0000,0000,0000,,This is something you can play with as \Nwell and see how far the optimiser goes. Dialogue: 0,0:22:59.97,0:23:03.37,Default,,0000,0000,0000,,And it's also good for people hacking \Nwith the JVM. Dialogue: 0,0:23:04.81,0:23:08.28,Default,,0000,0000,0000,,I'll move onto some stuff we did. Dialogue: 0,0:23:09.60,0:23:15.52,Default,,0000,0000,0000,,Last year we were working on the \Nbig data. Relatively new architecture Dialogue: 0,0:23:17.16,0:23:22.46,Default,,0000,0000,0000,,ARM64, it's called AArch64 in OpenJDK \Nland but ARM64 in Debian land. Dialogue: 0,0:23:23.79,0:23:26.77,Default,,0000,0000,0000,,We were a bit concerned because \Neverything's all shiny and new. Dialogue: 0,0:23:26.77,0:23:28.73,Default,,0000,0000,0000,,Has it been optimised correctly? Dialogue: 0,0:23:28.73,0:23:31.44,Default,,0000,0000,0000,,Are there any obvious things\Nwe need to optimise? Dialogue: 0,0:23:31.44,0:23:33.82,Default,,0000,0000,0000,,And we're also interested because\Neverything was so shiny and new Dialogue: 0,0:23:33.82,0:23:35.20,Default,,0000,0000,0000,,in the whole system. Dialogue: 0,0:23:35.20,0:23:38.97,Default,,0000,0000,0000,,Not just the JVM but the glibc and \Nthe kernel as well. Dialogue: 0,0:23:38.97,0:23:41.89,Default,,0000,0000,0000,,So how do we get a view of all of this? Dialogue: 0,0:23:41.89,0:23:48.66,Default,,0000,0000,0000,,I gave a quick talk before at the Debian \Nmini-conf before last [2014] about perf Dialogue: 0,0:23:49.54,0:23:52.65,Default,,0000,0000,0000,,so decided we could try and do some \Nclever things with Linux perf Dialogue: 0,0:23:52.65,0:23:57.66,Default,,0000,0000,0000,,and see if we could get some actual useful\Ndebugging information out. Dialogue: 0,0:23:57.66,0:24:02.13,Default,,0000,0000,0000,,We have the flame graphs that are quite \Nwell known. Dialogue: 0,0:24:02.13,0:24:08.19,Default,,0000,0000,0000,,We also have some previous work, Johannes \Nhad a special perf map agent that Dialogue: 0,0:24:08.19,0:24:13.35,Default,,0000,0000,0000,,could basically hook into perf and it \Nwould give you a nice way of running Dialogue: 0,0:24:13.35,0:24:20.00,Default,,0000,0000,0000,,perf-top for want of a better expression \Nand viewing the top Java function names. Dialogue: 0,0:24:21.58,0:24:24.94,Default,,0000,0000,0000,,This is really good work and it's really \Ngood for a particular use case Dialogue: 0,0:24:24.94,0:24:29.40,Default,,0000,0000,0000,,if you just want to do a quick snap shot \Nonce and see in that snap shot Dialogue: 0,0:24:29.64,0:24:32.10,Default,,0000,0000,0000,,where the hotspots where. Dialogue: 0,0:24:32.10,0:24:38.49,Default,,0000,0000,0000,,For a prolonged work load with all \Nthe functions being JIT'd multiple ways Dialogue: 0,0:24:38.49,0:24:42.16,Default,,0000,0000,0000,,with the optimisation going on and \Neverything moving around Dialogue: 0,0:24:42.16,0:24:46.76,Default,,0000,0000,0000,,it require a little bit more information \Nto be captured. Dialogue: 0,0:24:46.76,0:24:50.87,Default,,0000,0000,0000,,I decided to do a little bit of work on a \Nvery similar thing to perf-map-agent Dialogue: 0,0:24:51.41,0:24:55.72,Default,,0000,0000,0000,,but an agent that would capture it over \Na prolonged period of time. Dialogue: 0,0:24:55.72,0:24:59.23,Default,,0000,0000,0000,,Here's an example Flame graph, these are \Nall over the internet. Dialogue: 0,0:24:59.23,0:25:04.71,Default,,0000,0000,0000,,This is the SHA1 computation example that \NI gave at the beginning. Dialogue: 0,0:25:04.71,0:25:10.39,Default,,0000,0000,0000,,As expected the VM intrinsic SHA1 is the \Ntop one. Dialogue: 0,0:25:10.39,0:25:17.49,Default,,0000,0000,0000,,Not expected by me was this quite \Nsignificant chunk of CPU execution time. Dialogue: 0,0:25:17.49,0:25:21.41,Default,,0000,0000,0000,,And there was a significant amount of \Ntime being spent copying memory Dialogue: 0,0:25:21.41,0:25:28.08,Default,,0000,0000,0000,,from the mmapped memory \Nregion into a heap Dialogue: 0,0:25:28.08,0:25:31.32,Default,,0000,0000,0000,,and then that was passed to \Nthe crypto engine. Dialogue: 0,0:25:31.32,0:25:35.49,Default,,0000,0000,0000,,So we're doing a ton of memory copies for \Nno good reason. Dialogue: 0,0:25:35.49,0:25:38.66,Default,,0000,0000,0000,,That essentially highlighted an example. Dialogue: 0,0:25:38.66,0:25:42.49,Default,,0000,0000,0000,,That was an assumption I made about Java \Nto begin with which was if you do Dialogue: 0,0:25:42.49,0:25:45.11,Default,,0000,0000,0000,,the equivalent of mmap it should just \Nwork like mmap right? Dialogue: 0,0:25:45.11,0:25:48.12,Default,,0000,0000,0000,,You should just be able to address the \Nmemory. That is not the case.\N Dialogue: 0,0:25:48.12,0:25:53.84,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,0:25:53.84,0:25:59.20,Default,,0000,0000,0000,,into safe heap memory first. And that is \Nwhat was slowing down the programs. Dialogue: 0,0:25:59.20,0:26:04.58,Default,,0000,0000,0000,,If that was omitted you could make \Nthe SHA1 computation even quicker. Dialogue: 0,0:26:04.58,0:26:09.02,Default,,0000,0000,0000,,So that would be the logical target you \Nwould want to optimise. Dialogue: 0,0:26:09.02,0:26:12.01,Default,,0000,0000,0000,,I wanted to extend Johannes' work \Nwith something called a Dialogue: 0,0:26:12.01,0:26:15.74,Default,,0000,0000,0000,,Java Virtual Machine Tools Interface \Nprofiling agent. Dialogue: 0,0:26:16.87,0:26:22.65,Default,,0000,0000,0000,,This is part of the Java Virtual Machine \Nstandard as you can make a special library Dialogue: 0,0:26:22.65,0:26:24.51,Default,,0000,0000,0000,,and then hook this into the JVM. Dialogue: 0,0:26:24.51,0:26:28.20,Default,,0000,0000,0000,,And the JVM can expose quite a few \Nthings to the library. Dialogue: 0,0:26:28.20,0:26:32.41,Default,,0000,0000,0000,,It exposes a reasonable amount of \Ninformation as well. Dialogue: 0,0:26:32.41,0:26:39.17,Default,,0000,0000,0000,,Perf as well has the ability to look \Nat map files natively. Dialogue: 0,0:26:39.84,0:26:44.36,Default,,0000,0000,0000,,If you are profiling JavaScript, or \Nsomething similar, I think the Dialogue: 0,0:26:44.36,0:26:48.40,Default,,0000,0000,0000,,Google V8 JavaScript engine will write \Nout a special map file that says Dialogue: 0,0:26:48.40,0:26:52.72,Default,,0000,0000,0000,,these program counter addresses correspond\Nto these function names. Dialogue: 0,0:26:52.72,0:26:56.99,Default,,0000,0000,0000,,I decided to use that in a similar way to \Nwhat Johannes did for the extended Dialogue: 0,0:26:56.99,0:27:02.48,Default,,0000,0000,0000,,profiling agent but I also decided to \Ncapture some more information as well. Dialogue: 0,0:27:05.26,0:27:09.97,Default,,0000,0000,0000,,I decided to capture the disassembly \Nso when we run perf annotate Dialogue: 0,0:27:09.97,0:27:13.40,Default,,0000,0000,0000,,we can see the actual JVM bytecode \Nin our annotation. Dialogue: 0,0:27:13.40,0:27:17.26,Default,,0000,0000,0000,,We can see how it was JIT'd at the \Ntime when it was JIT'd. Dialogue: 0,0:27:17.26,0:27:19.66,Default,,0000,0000,0000,,We can see where the hotspots where. Dialogue: 0,0:27:19.66,0:27:22.82,Default,,0000,0000,0000,,And that's good. But we can go \Neven better. Dialogue: 0,0:27:22.82,0:27:29.17,Default,,0000,0000,0000,,We can run an annotated trace that \Ncontains the Java class, Dialogue: 0,0:27:29.17,0:27:33.96,Default,,0000,0000,0000,,the Java method and the bytecode all in \None place at the same time. Dialogue: 0,0:27:33.96,0:27:38.95,Default,,0000,0000,0000,,You can see everything from the JVM \Nat the same place. Dialogue: 0,0:27:38.95,0:27:43.94,Default,,0000,0000,0000,,This works reasonably well because the \Nperf interface is extremely extensible. Dialogue: 0,0:27:43.94,0:27:47.69,Default,,0000,0000,0000,,And again we can do entire \Nsystem optimisation. Dialogue: 0,0:27:47.69,0:27:51.78,Default,,0000,0000,0000,,The bits in red here are the Linux kernel. Dialogue: 0,0:27:51.78,0:27:54.99,Default,,0000,0000,0000,,Then we got into libraries. Dialogue: 0,0:27:54.99,0:27:57.94,Default,,0000,0000,0000,,And then we got into Java and more \Nlibraries as well. Dialogue: 0,0:27:57.94,0:28:02.34,Default,,0000,0000,0000,,So we can see everything from top to \Nbottom in one fell swoop. Dialogue: 0,0:28:04.12,0:28:07.61,Default,,0000,0000,0000,,This is just a quick slide showing the \Nmechanisms employed. Dialogue: 0,0:28:07.61,0:28:11.67,Default,,0000,0000,0000,,Essentially we have this agent which is \Na shared object file. Dialogue: 0,0:28:11.67,0:28:16.39,Default,,0000,0000,0000,,And this will spit out useful files here \Nin a standard way. Dialogue: 0,0:28:16.39,0:28:25.62,Default,,0000,0000,0000,,And the Linux perf basically just records \Nthe perf data dump file as normal. Dialogue: 0,0:28:27.16,0:28:29.58,Default,,0000,0000,0000,,We have 2 sets of recording going on. Dialogue: 0,0:28:29.58,0:28:35.23,Default,,0000,0000,0000,,To report it it's very easy to do \Nnormal reporting with the PID map. Dialogue: 0,0:28:35.23,0:28:40.82,Default,,0000,0000,0000,,This is just out of the box, works with \Nthe Google V8 engine as well. Dialogue: 0,0:28:40.82,0:28:45.08,Default,,0000,0000,0000,,If you want to do very clever annotations \Nperf has the ability to have Dialogue: 0,0:28:45.08,0:28:47.69,Default,,0000,0000,0000,,Python scripts passed to it. Dialogue: 0,0:28:47.69,0:28:53.52,Default,,0000,0000,0000,,So you can craft quite a dodgy Python \Nscript and that can interface Dialogue: 0,0:28:53.52,0:28:55.37,Default,,0000,0000,0000,,with the perf annotation output. Dialogue: 0,0:28:55.37,0:29:00.24,Default,,0000,0000,0000,,That's how I was able to get the extra \NJava information in the same annotation. Dialogue: 0,0:29:00.24,0:29:05.05,Default,,0000,0000,0000,,And this is really easy to do; it's quite \Neasy to knock the script up. Dialogue: 0,0:29:05.05,0:29:10.22,Default,,0000,0000,0000,,And again the only thing we do for this \Nprofiling is we hook in the profiling Dialogue: 0,0:29:10.22,0:29:13.44,Default,,0000,0000,0000,,agent which dumps out various things. Dialogue: 0,0:29:13.44,0:29:18.33,Default,,0000,0000,0000,,We preserve the frame pointer because \Nthat makes things considerably easier Dialogue: 0,0:29:18.33,0:29:21.37,Default,,0000,0000,0000,,on winding. This will effect \Nperformance a little bit. Dialogue: 0,0:29:21.37,0:29:25.91,Default,,0000,0000,0000,,And again when we're reporting we just \Nhook in a Python script. Dialogue: 0,0:29:25.91,0:29:29.70,Default,,0000,0000,0000,,It's really easy to hook everything in \Nand get it working. Dialogue: 0,0:29:32.69,0:29:37.32,Default,,0000,0000,0000,,At the moment we have a JVMTI agent. It's \Nactually on http://git.linaro.org now. Dialogue: 0,0:29:38.25,0:29:42.15,Default,,0000,0000,0000,,Since I gave this talk Google have \Nextended perf anyway so it will do Dialogue: 0,0:29:42.15,0:29:45.40,Default,,0000,0000,0000,,quite a lot of similar things out of the \Nbox anyway. Dialogue: 0,0:29:45.40,0:29:49.75,Default,,0000,0000,0000,,It's worth having a look at the \Nlatest perf. Dialogue: 0,0:29:49.75,0:29:54.28,Default,,0000,0000,0000,,These techniques in this slide deck can be\Nused obviously in other JITs quite easily. Dialogue: 0,0:29:54.28,0:29:59.31,Default,,0000,0000,0000,,The fact that perf is so easy to extend \Nwith scripts can be useful Dialogue: 0,0:29:59.31,0:30:01.22,Default,,0000,0000,0000,,for other things. Dialogue: 0,0:30:01.22,0:30:05.77,Default,,0000,0000,0000,,And OpenJDK has a significant amount of \Ncleverness associated with it that Dialogue: 0,0:30:05.77,0:30:10.05,Default,,0000,0000,0000,,I thought was very surprising and good. \NSo that's what I covered in the talk. Dialogue: 0,0:30:13.00,0:30:17.85,Default,,0000,0000,0000,,These are basically references to things \Nlike command line arguments Dialogue: 0,0:30:17.85,0:30:20.49,Default,,0000,0000,0000,,and the Flame graphs and stuff like that. Dialogue: 0,0:30:20.49,0:30:26.31,Default,,0000,0000,0000,,If anyone is interested in playing with \NOpenJDK on ARM64 I'd suggest going here: Dialogue: 0,0:30:26.31,0:30:31.01,Default,,0000,0000,0000,,http://openjdk.linaro.org\NWhere the most recent builds are. Dialogue: 0,0:30:31.01,0:30:36.00,Default,,0000,0000,0000,,Obviously fixes are going in upstream and \Nthey're going into distributions as well. Dialogue: 0,0:30:36.00,0:30:40.11,Default,,0000,0000,0000,,They're included in OpenJDK so it should \Nbe good as well. Dialogue: 0,0:30:41.33,0:30:44.87,Default,,0000,0000,0000,,I've run through quite a few fundamental \Nthings reasonably quickly. Dialogue: 0,0:30:44.87,0:30:48.27,Default,,0000,0000,0000,,I'd be happy to accept any questions \Nor comments Dialogue: 0,0:30:54.16,0:30:57.30,Default,,0000,0000,0000,,And if you want to talk to me privately \Nabout Java afterwards feel free to Dialogue: 0,0:30:57.30,0:30:59.13,Default,,0000,0000,0000,,when no-one's looking. Dialogue: 0,0:31:06.90,0:31:12.70,Default,,0000,0000,0000,,[Audience] Applause Dialogue: 0,0:31:13.32,0:31:19.03,Default,,0000,0000,0000,,[Audience] It's not really a question so \Nmuch as a comment. Dialogue: 0,0:31:19.03,0:31:31.88,Default,,0000,0000,0000,,Last mini-Deb conf we had a talk about \Nusing the JVM with other languages. Dialogue: 0,0:31:31.88,0:31:35.84,Default,,0000,0000,0000,,And it seems to me that all this would \Napply even if you hate Java programming Dialogue: 0,0:31:35.84,0:31:39.36,Default,,0000,0000,0000,,language and want to write in, I don't \Nknow, lisp or something instead Dialogue: 0,0:31:39.36,0:31:42.42,Default,,0000,0000,0000,,if you've got a lisp system that can \Ngenerate JVM bytecode. Dialogue: 0,0:31:42.42,0:31:48.13,Default,,0000,0000,0000,,[Presenter] Yeah, totally. And the other \Nbig data language we looked at was Scala. Dialogue: 0,0:31:49.16,0:31:53.42,Default,,0000,0000,0000,,It uses the JVM back end but a completely \Ndifferent language on the front. Dialogue: 0,0:32:03.88,0:32:08.10,Default,,0000,0000,0000,,Cheers guys.