Update kryo to 4.0.0

- WARN:Serialized bytes are not binary compatible
- Release summary: https://github.com/EsotericSoftware/kryo/releases/tag/kryo-parent-4.0.0
- KryoNamespace: stop using direct buffer

This might fix ONOS-5130

Change-Id: I6e1e00f147a90ae8bfded78b2fa3a77158602c76
diff --git a/features/features.xml b/features/features.xml
index cad8e6a..09dd249 100644
--- a/features/features.xml
+++ b/features/features.xml
@@ -40,9 +40,9 @@
         <bundle>mvn:io.dropwizard.metrics/metrics-json/3.1.2</bundle>
         <bundle>mvn:com.eclipsesource.minimal-json/minimal-json/0.9.4</bundle>
 
-        <bundle>mvn:com.esotericsoftware/kryo/3.0.3</bundle>
-        <bundle>mvn:com.esotericsoftware/reflectasm/1.11.0</bundle>
-        <bundle>mvn:org.ow2.asm/asm/5.0.3</bundle>
+        <bundle>mvn:com.esotericsoftware/kryo/4.0.0</bundle>
+        <bundle>mvn:com.esotericsoftware/reflectasm/1.11.3</bundle>
+        <bundle>mvn:org.ow2.asm/asm/5.0.4</bundle>
         <bundle>mvn:com.esotericsoftware/minlog/1.3.0</bundle>
         <bundle>mvn:org.objenesis/objenesis/2.2</bundle>
 
diff --git a/lib/BUCK b/lib/BUCK
index b6895f5..c5b609c 100644
--- a/lib/BUCK
+++ b/lib/BUCK
@@ -1,4 +1,4 @@
-# ***** This file was auto-generated at Thu Aug 11 12:54:15 PDT 2016. Do not edit this file manually. *****
+# ***** This file was auto-generated at Tue Aug 16 15:39:29 PDT 2016. Do not edit this file manually. *****
 osgi_feature_group(
   name = 'COMPILE',
   visibility = ['PUBLIC'],
@@ -124,10 +124,10 @@
 
 remote_jar (
   name = 'asm',
-  out = 'asm-5.0.3.jar',
-  url = 'mvn:org.ow2.asm:asm:jar:5.0.3',
-  sha1 = 'dcc2193db20e19e1feca8b1240dbbc4e190824fa',
-  maven_coords = 'org.ow2.asm:asm:5.0.3',
+  out = 'asm-5.0.4.jar',
+  url = 'mvn:org.ow2.asm:asm:jar:5.0.4',
+  sha1 = '0da08b8cce7bbf903602a25a3a163ae252435795',
+  maven_coords = 'org.ow2.asm:asm:5.0.4',
   visibility = [ 'PUBLIC' ],
 )
 
@@ -628,10 +628,10 @@
 
 remote_jar (
   name = 'kryo',
-  out = 'kryo-3.0.3.jar',
-  url = 'mvn:com.esotericsoftware:kryo:jar:3.0.3',
-  sha1 = '01ebca99f633ef31484176a727093e78c7fa43e7',
-  maven_coords = 'com.esotericsoftware:kryo:3.0.3',
+  out = 'kryo-4.0.0.jar',
+  url = 'mvn:com.esotericsoftware:kryo:jar:4.0.0',
+  sha1 = '9f5c64c1315ec79bee0f56bb88e4ae94b65048ce',
+  maven_coords = 'com.esotericsoftware:kryo:4.0.0',
   visibility = [ 'PUBLIC' ],
 )
 
diff --git a/lib/deps.json b/lib/deps.json
index ec745b8..fec42a8 100644
--- a/lib/deps.json
+++ b/lib/deps.json
@@ -85,7 +85,7 @@
   "artifacts": {
     "gmetric4j": "mvn:info.ganglia.gmetric4j:gmetric4j:1.0.10",
     "aopalliance-repackaged": "mvn:org.glassfish.hk2.external:aopalliance-repackaged:2.4.0-b34",
-    "asm": "mvn:org.ow2.asm:asm:5.0.3",
+    "asm": "mvn:org.ow2.asm:asm:5.0.4",
     "atomix": "mvn:io.atomix:atomix-all:1.0.0-rc9",
     "commons-codec": "mvn:commons-codec:commons-codec:1.10",
     "commons-collections": "mvn:commons-collections:commons-collections:3.2.2",
@@ -141,7 +141,7 @@
     "jsch": "mvn:com.jcraft:jsch:0.1.53",
     "jsr305": "mvn:com.google.code.findbugs:jsr305:3.0.1",
     "junit": "mvn:junit:junit:4.12",
-    "kryo": "mvn:com.esotericsoftware:kryo:3.0.3",
+    "kryo": "mvn:com.esotericsoftware:kryo:4.0.0",
     "mapdb": "mvn:org.mapdb:mapdb:1.0.9",
     "metrics-core": "mvn:io.dropwizard.metrics:metrics-core:3.1.0",
     "metrics-ganglia": "mvn:io.dropwizard.metrics:metrics-ganglia:3.1.2",
diff --git a/lib/pom.xml b/lib/pom.xml
index e7cb764..118586c 100644
--- a/lib/pom.xml
+++ b/lib/pom.xml
@@ -263,18 +263,17 @@
             <dependency>
                 <groupId>com.esotericsoftware</groupId>
                 <artifactId>kryo</artifactId>
-                <version>3.0.3</version>
+                <version>4.0.0</version>
             </dependency>
             <dependency>
                 <groupId>com.esotericsoftware</groupId>
                 <artifactId>reflectasm</artifactId>
-                <version>1.11.0</version>
-                <type>bundle</type>
+                <version>1.11.3</version>
             </dependency>
             <dependency>
                 <groupId>org.ow2.asm</groupId>
                 <artifactId>asm</artifactId>
-                <version>5.0.3</version>
+                <version>5.0.4</version>
             </dependency>
             <dependency>
                 <groupId>com.esotericsoftware</groupId>
diff --git a/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckLibGenerator.java b/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckLibGenerator.java
index d915ddd..5b67a5c 100644
--- a/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckLibGenerator.java
+++ b/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckLibGenerator.java
@@ -174,6 +174,7 @@
             writer.write(String.format(
                     "# ***** This file was auto-generated at %s. Do not edit this file manually. *****\n",
                     new Date().toString()));
+            writer.write("# ***** Use onos-lib-gen *****\n");
             libraries.forEach(library -> writer.print(library.getBuckFragment()));
             artifacts.forEach(artifact -> writer.print(artifact.getBuckFragment()));
             writer.flush();
diff --git a/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java b/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
index 5fb1afc..7328c8d 100644
--- a/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
+++ b/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
@@ -21,6 +21,7 @@
 import com.esotericsoftware.kryo.io.ByteBufferInput;
 import com.esotericsoftware.kryo.io.ByteBufferOutput;
 import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
 import com.esotericsoftware.kryo.pool.KryoCallback;
 import com.esotericsoftware.kryo.pool.KryoFactory;
 import com.esotericsoftware.kryo.pool.KryoPool;
@@ -271,19 +272,12 @@
      * @return serialized bytes
      */
     public byte[] serialize(final Object obj, final int bufferSize) {
-        ByteBufferOutput out = new ByteBufferOutput(bufferSize, MAX_BUFFER_SIZE);
-        try {
-            Kryo kryo = borrow();
-            try {
-                kryo.writeClassAndObject(out, obj);
-                out.flush();
-                return out.toBytes();
-            } finally {
-                release(kryo);
-            }
-        } finally {
-            out.release();
-        }
+        Output out = new Output(bufferSize, MAX_BUFFER_SIZE);
+        return pool.run(kryo -> {
+            kryo.writeClassAndObject(out, obj);
+            out.flush();
+            return out.toBytes();
+        });
     }
 
     /**