Hacker News new | past | comments | ask | show | jobs | submit login
Building Memory-Efficient Java Applications (2009) [pdf] (virginia.edu)
50 points by hokkos on Sept 1, 2015 | hide | past | favorite | 10 comments



IMO This without the talk is not a very usable read. Maybe it's because I've already knew 95% of the concepts it was showing but I felt that the talk must have been pretty interesting as most of the presentation is just bullets points of complex topics.

Does anyone have the audio of it? Also with memory is becoming less of a problem so people tend to completely ignore it, it's nice to see something like this.


I remember seeing this on an IBM-branded site. A cursory search gave me this: http://www.ibm.com/developerworks/library/j-codetoheap/

...which is not the exact same presentation, but the subjects it touches on seem to overlap.


I tend to find the overhead of the JVM appears to contribute the most. If I have -Xmx 128MB for example, around 200MB will often be shown in Windows task manager, or whatever.

Maybe this is addressed in the talk, any my "overhead" is actually my own mis-used data space which I am not aware of.


The Xmx flag controls the maximum heap size. The JVM has other things that are outside of the heap (the JVM process itself, the code cache, native buffers, resource handles, etc.).


That's my point, perhaps clumsily put. It's the stuff outside the heap that appears to take up much of the space.


Please correct me if I'm wrong...

Q: What is the size ratio of Integer to int?

An int is 4 bytes, an Integer additionally has a 2 word object header (8 bytes) and a 4 byte reference pointing to it. This adds up to 12 bytes for the object, which is rounded up to 16 bytes, because Hotspot aligns objects to 8 byte boundaries. Including the reference, the Integer needs 20 bytes, or 5 times as much as an int.

Q: How many bytes in an 8-character String?

  * object header: 8 bytes
  * reference to char[] storing the value: 4 bytes
  * int field to cache hashcode: 4 bytes
  -> 16 bytes for "wrapper"
  * char[] storing the value:
      8 characters in UTF16: 16 bytes
      object header: 8 bytes
      length field: 4 bytes length
      -> 28 bytes, rounded up to 32 bytes
  total: 48 bytes

Q: Which of the following is true about HashSet relative to HashMap

d. does less, bigger: HashSet is a wrapper around HashMap

Q: Put the following 2-element collections in size order: ArrayList, HashSet, LinkedList, HashMap

Excluding the size of the actual elements:

  * ArrayList, created with initial capacity of 2 (vs. default of 10):
      * object header: 8 bytes
      * size int: 4 bytes
      * reference to Object[] holding element data: 4 bytes
      -> 16 bytes for wrapper
      * element data with 2 pointers: 2*4 bytes + 12 bytes, rounded
        up to 24 bytes
      -> 40 bytes total

  * LinkedList:
      * object header: 8 bytes
      * size int: 4 bytes
      * references to first + last node: 8 bytes
      -> 20 bytes, rounded up to 24 bytes
      * nodes (2x):
          * object header: 8 bytes
          * references to previous and next item: 8 bytes
          * reference to element data: 4 bytes
          -> 20 bytes, rounded up to 24
      -> 72 bytes total

  * HashMap, created with initial capacity of 2 (vs. 16) and default
    load factor of 0.75
      * object header: 8 bytes
      * modification count int: 4 bytes
      * size int: 4 bytes
      * load factor float: 4 bytes
      * entry set: ?
      * resizing threshold int: 4 bytes
      * pointer to hash table: 4 bytes
      -> 28 bytes for wrapper, rounded up to 32 bytes
      * hash table (Node[]):
          * object header: 8 bytes
          * length field: 4 bytes
          * pointers: 4 * 4 bytes
          -> 28 bytes, rounded up to 32 bytes
      * Node objects (2x):
          * object header: 8 bytes
          * hashcode int: 4 bytes
          * pointer to next node in chain: 4 bytes
          * pointer to element data: 4 bytes
          -> 20 bytes, rounded up to 24 bytes
      -> total of 120 bytes

  * HashSet, created with initial capacity of 2 (vs. 16) and default
    load factor of 0.75
      * object header: 8 bytes
      * pointer to HashMap: 4 bytes
      -> 12 bytes for wrapper, rounded up to 16
      * HashMap: 120 bytes
      -> 132 bytes total


I couldn't get this either . "Forbidden"


is the talk available?


Not from the same talk, but the same conference so probably not?

"Comment from Dave Mandelin Time: January 25, 2010, 2:15 pm

I asked the conference organizers and unfortunately they didn’t videorecord the talks."[1]

[1] https://blog.mozilla.org/dmandelin/2009/06/02/tracemonkeypld...


probably you want to read the books by Charlie Hunt or Oaks if you can't find the vid




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: