You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sirona.apache.org by ol...@apache.org on 2014/03/06 01:02:54 UTC
svn commit: r1574726 -
/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/tracking/InMemoryPathTrackingDataStore.java
Author: olamy
Date: Thu Mar 6 00:02:54 2014
New Revision: 1574726
URL: http://svn.apache.org/r1574726
Log:
use a static field for unsafe
Modified:
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/tracking/InMemoryPathTrackingDataStore.java
Modified: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/tracking/InMemoryPathTrackingDataStore.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/tracking/InMemoryPathTrackingDataStore.java?rev=1574726&r1=1574725&r2=1574726&view=diff
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/tracking/InMemoryPathTrackingDataStore.java (original)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/store/tracking/InMemoryPathTrackingDataStore.java Thu Mar 6 00:02:54 2014
@@ -47,6 +47,24 @@ import java.util.concurrent.ConcurrentMa
public class InMemoryPathTrackingDataStore
implements PathTrackingDataStore, CollectorPathTrackingDataStore
{
+
+ private static Unsafe UNSAFE;
+
+
+ static
+ {
+ try
+ {
+ Field f = Unsafe.class.getDeclaredField( "theUnsafe" );
+ f.setAccessible( true );
+ UNSAFE = (Unsafe) f.get( null );
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( e.getMessage(), e );
+ }
+ }
+
/**
* store path track tracking entries list per path tracking id
* the value is the memory address
@@ -151,7 +169,7 @@ public class InMemoryPathTrackingDataSto
long offset = pointer.offheapPointer;
for ( int pos = 0; pos < length; pos++ )
{
- bytes[pos] = getUnsafe().getByte( pos + offset );
+ bytes[pos] = UNSAFE.getByte( pos + offset );
}
return bytes;
}
@@ -172,13 +190,13 @@ public class InMemoryPathTrackingDataSto
byte[] bytes = serialize( entry );
if ( bytes != null )
{
- long offheapPointer = getUnsafe().allocateMemory( bytes.length );
+ long offheapPointer = UNSAFE.allocateMemory( bytes.length );
Pointer pointer = new Pointer();
pointer.offheapPointer = offheapPointer;
pointer.size = bytes.length;
for ( int i = 0, size = bytes.length; i < size; i++ )
{
- getUnsafe().putByte( offheapPointer + i, bytes[i] );
+ UNSAFE.putByte( offheapPointer + i, bytes[i] );
}
buffers.add( pointer );
@@ -196,7 +214,7 @@ public class InMemoryPathTrackingDataSto
// clear entries to not wait gc
for ( Pointer pointer : entry.getValue() )
{
- getUnsafe().freeMemory( pointer.offheapPointer );
+ UNSAFE.freeMemory( pointer.offheapPointer );
}
}
pathTrackingEntries = new ConcurrentHashMap<String, List<Pointer>>( 50 );
@@ -269,21 +287,4 @@ public class InMemoryPathTrackingDataSto
}
- //if bytebuffer is not efficient enough use unsafe directly
- private static Unsafe getUnsafe()
- {
- try
- {
- Field f = Unsafe.class.getDeclaredField( "theUnsafe" );
- f.setAccessible( true );
- return (Unsafe) f.get( null );
- }
- catch ( Exception e )
- {
-
- }
-
- return null;
- }
-
}