Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions hbase-noop-htrace/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4 changes: 4 additions & 0 deletions hbase-unsafe/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.function.BiConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Delegate all methods of {@link HBaseUnsafeInternal}, so we will not touch the actual
* {@code sun.misc.Unsafe} class until we actually call the methods.
* Delegate all methods of {@link HBaseUnsafeInternal} and {@link HBaseSignalInternal} so we will
* not touch the actual {@code sun.misc.Unsafe} and {@code sun.misc.Signal} classes until we
* actually call the methods.
*/
public final class HBaseUnsafe {
public final class HBasePlatformDependent {

private static final String CLASS_NAME = "sun.misc.Unsafe";
private static final Logger LOG = LoggerFactory.getLogger(HBaseUnsafe.class);
private static final Logger LOG = LoggerFactory.getLogger(HBasePlatformDependent.class);
private static final boolean AVAIL;
private static final boolean UNALIGNED;

Expand Down Expand Up @@ -174,9 +176,8 @@ private static boolean checkUnaligned() {
m.setAccessible(true);
return (Boolean) m.invoke(null);
} catch (Exception e) {
LOG.warn("java.nio.Bits#unaligned() check failed."
+ "Unsafe based read/write of primitive types won't be used",
e);
LOG.warn("java.nio.Bits#unaligned() check failed." +
"Unsafe based read/write of primitive types won't be used", e);
}
return false;
}
Expand All @@ -185,7 +186,7 @@ private static boolean checkUnaligned() {
* @return true when running JVM is having sun's Unsafe package available in it and it is
* accessible.
*/
public static boolean isAvailable() {
public static boolean isUnsafeAvailable() {
return AVAIL;
}

Expand All @@ -197,7 +198,7 @@ public static boolean unaligned() {
return UNALIGNED;
}

private HBaseUnsafe() {
private HBasePlatformDependent() {
// private constructor to avoid instantiation
}

Expand Down Expand Up @@ -354,7 +355,7 @@ public static void setMemory(long address, long bytes, byte value) {
}

public static void copyMemory(Object srcBase, long srcOffset, Object destBase, long destOffset,
long bytes) {
long bytes) {
HBaseUnsafeInternal.copyMemory(srcBase, srcOffset, destBase, destOffset, bytes);
}

Expand Down Expand Up @@ -403,7 +404,7 @@ public static int pageSize() {
}

public static Class<?> defineClass(String name, byte[] b, int off, int len, ClassLoader loader,
ProtectionDomain protectionDomain) {
ProtectionDomain protectionDomain) {
return HBaseUnsafeInternal.defineClass(name, b, off, len, loader, protectionDomain);
}

Expand Down Expand Up @@ -559,4 +560,13 @@ public static void fullFence() {
HBaseUnsafeInternal.fullFence();
}

/**
* Delegate {@code sun.misc.Signal}.
* @param signal the name of the signal, such as 'HUP'.
* @param handler the handler of the signal, the first parameter is the number of the signal,
* while the second one is the name of the sinal.
*/
public static void handle(String signal, BiConsumer<Integer, String> handler) {
HBaseSignalInternal.handle(signal, handler);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.unsafe;

import java.util.function.BiConsumer;
import sun.misc.Signal;

/**
* Delegation of {@code sun.misc.Signal}.
*/
@SuppressWarnings("restriction")
public final class HBaseSignalInternal {

private HBaseSignalInternal() {
}

public static void handle(String signal, BiConsumer<Integer, String> handler) {
Signal.handle(new Signal(signal), s -> handler.accept(s.getNumber(), s.getName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class TestHBaseUnsafe {

@Test
public void test() {
assumeTrue(HBaseUnsafe.isAvailable());
assumeTrue(HBasePlatformDependent.isUnsafeAvailable());
byte[] arr = new byte[4];
int arrayBaseOffset = HBaseUnsafe.arrayBaseOffset(arr.getClass());
HBaseUnsafe.putInt(arr, arrayBaseOffset, 123456);
assertEquals(123456, HBaseUnsafe.getInt(arr, arrayBaseOffset));
int arrayBaseOffset = HBasePlatformDependent.arrayBaseOffset(arr.getClass());
HBasePlatformDependent.putInt(arr, arrayBaseOffset, 123456);
assertEquals(123456, HBasePlatformDependent.getInt(arr, arrayBaseOffset));
}
}