Skip to content

Commit

Permalink
GEODE-130: Cleanup internal API warnings. (apache#3872)
Browse files Browse the repository at this point in the history
* Isolate API warnings to unsafe module.
* Ignore API warnings on unsafe module only.
  • Loading branch information
jake-at-work authored Aug 22, 2019
1 parent 7aeb882 commit 7efc2cd
Show file tree
Hide file tree
Showing 35 changed files with 611 additions and 116 deletions.
6 changes: 6 additions & 0 deletions boms/geode-all-bom/src/test/resources/expected-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,12 @@
<version>1.11.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-unsafe</artifactId>
<version>1.10.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-wan</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -160,13 +159,13 @@ public DockerizedExecHandle(DockerizedTestExtension testExtension, String displa
this.timeoutMillis = timeoutMillis;
this.daemon = daemon;
this.executor = executor;
this.lock = new ReentrantLock();
this.stateChanged = lock.newCondition();
this.state = ExecHandleState.INIT;
this.buildCancellationToken = buildCancellationToken;
this.testExtension = testExtension;
lock = new ReentrantLock();
stateChanged = lock.newCondition();
state = ExecHandleState.INIT;
shutdownHookAction = new ExecHandleShutdownHookAction(this);
broadcast = new ListenerBroadcast<ExecHandleListener>(ExecHandleListener.class);
broadcast = new ListenerBroadcast<>(ExecHandleListener.class);
broadcast.addAll(listeners);
}

Expand Down Expand Up @@ -214,7 +213,7 @@ private void setState(ExecHandleState state) {
try {
LOGGER.debug("Changing state to: {}", state);
this.state = state;
this.stateChanged.signalAll();
stateChanged.signalAll();
} finally {
lock.unlock();
}
Expand All @@ -223,7 +222,7 @@ private void setState(ExecHandleState state) {
private boolean stateIn(ExecHandleState... states) {
lock.lock();
try {
return Arrays.asList(states).contains(this.state);
return Arrays.asList(states).contains(state);
} finally {
lock.unlock();
}
Expand All @@ -235,7 +234,7 @@ private void setEndStateInfo(ExecHandleState newState, int exitValue, Throwable
ExecHandleState currentState;
lock.lock();
try {
currentState = this.state;
currentState = state;
} finally {
lock.unlock();
}
Expand All @@ -254,7 +253,7 @@ private void setEndStateInfo(ExecHandleState newState, int exitValue, Throwable
lock.lock();
try {
setState(newState);
this.execResult = newResult;
execResult = newResult;
} finally {
lock.unlock();
}
Expand Down Expand Up @@ -330,8 +329,8 @@ public void abort() {
format("Cannot abort process '%s' because it is not in started or detached state",
displayName));
}
this.execHandleRunner.abortProcess();
this.waitForFinish();
execHandleRunner.abortProcess();
waitForFinish();
} finally {
lock.unlock();
}
Expand Down Expand Up @@ -427,7 +426,7 @@ public int getTimeout() {
public Process runContainer() {
try {
DockerClient client = testExtension.getClient();
CreateContainerCmd createCmd = client.createContainerCmd(testExtension.getImage().toString())
CreateContainerCmd createCmd = client.createContainerCmd(testExtension.getImage())
.withTty(false)
.withStdinOpen(true)
.withWorkingDir(directory.getAbsolutePath());
Expand All @@ -439,7 +438,7 @@ public Process runContainer() {
createCmd.withUser(user);
}
bindVolumes(createCmd);
List<String> cmdLine = new ArrayList<String>();
List<String> cmdLine = new ArrayList<>();
cmdLine.add(command);
cmdLine.addAll(arguments);
createCmd.withCmd(cmdLine);
Expand Down Expand Up @@ -482,18 +481,19 @@ private void invokeIfNotNull(Closure closure, Object... args) {
}

private List<String> getEnv() {
List<String> env = new ArrayList<String>();
List<String> env = new ArrayList<>();
for (Map.Entry<String, String> e : environment.entrySet()) {
env.add(e.getKey() + "=" + e.getValue());
}
return env;
}

private void bindVolumes(CreateContainerCmd cmd) {
List<Volume> volumes = new ArrayList<Volume>();
List<Bind> binds = new ArrayList<Bind>();
for (Iterator it = testExtension.getVolumes().entrySet().iterator(); it.hasNext(); ) {
Map.Entry<Object, Object> e = (Map.Entry<Object, Object>) it.next();
List<Volume> volumes = new ArrayList<>();
List<Bind> binds = new ArrayList<>();
for (Object o : testExtension.getVolumes().entrySet()) {
@SuppressWarnings("unchecked")
Map.Entry<Object, Object> e = (Map.Entry<Object, Object>) o;
Volume volume = new Volume(e.getValue().toString());
Bind bind = new Bind(e.getKey().toString(), volume);
binds.add(bind);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ lib/fastutil-8.2.2.jar
lib/findbugs-annotations-1.3.9-1.jar
lib/geo-0.7.1.jar
lib/geode-common-0.0.0.jar
lib/geode-unsafe-0.0.0.jar
lib/geode-connectors-0.0.0.jar
lib/geode-core-0.0.0.jar
lib/geode-cq-0.0.0.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ commons-validator-1.6.jar
fastutil-8.2.2.jar
geo-0.7.1.jar
geode-common-0.0.0.jar
geode-unsafe-0.0.0.jar
geode-connectors-0.0.0.jar
geode-core-0.0.0.jar
geode-cq-0.0.0.jar
Expand Down
3 changes: 2 additions & 1 deletion geode-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ dependencies {
//Currently it has ExpirationAction in it, which is an API dependency in core, but
//probably does not belong in this project
api(project(':geode-common'))

api(project(':geode-unsafe'))

//geode-management currently has pieces of the public API
//copied into it, so it is an API dependency
api(project(':geode-management'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package org.apache.geode.distributed.internal.unsafe;

import org.apache.geode.unsafe.internal.sun.misc.Signal;

/**
* The RegisterSignalHandlerSupport class is an ugly hack!
* </p>
Expand All @@ -24,9 +26,7 @@
public abstract class RegisterSignalHandlerSupport {

public static void registerSignalHandlers() {
sun.misc.Signal.handle(new sun.misc.Signal("INT"), new sun.misc.SignalHandler() {
@Override
public void handle(final sun.misc.Signal sig) {}
Signal.handle(new Signal("INT"), sig -> {
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.apache.geode.annotations.Immutable;
import org.apache.geode.internal.lang.SystemUtils;
import org.apache.geode.pdx.internal.unsafe.UnsafeWrapper;
import org.apache.geode.unsafe.internal.sun.misc.Unsafe;

/**
* The class provides info about some JVM characteristics
Expand All @@ -31,11 +31,11 @@ public class JvmSizeUtils {
private static final int objectHeaderSize;

@Immutable
private static final UnsafeWrapper unsafe;
private static final Unsafe unsafe;
static {
UnsafeWrapper tmp = null;
Unsafe tmp = null;
try {
tmp = new UnsafeWrapper();
tmp = new Unsafe();
} catch (RuntimeException ignore) {
} catch (Error ignore) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,7 @@ private void runSelectorLoop() {
} catch (ClosedChannelException cce) {
// for bug bug 38474
finishCon(sc);
} catch (IOException | RuntimeException ex) {

} catch (RuntimeException ex) {
finishCon(sc);
logger.warn("ignoring", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import java.io.ObjectStreamField;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.AbstractSet;
Expand All @@ -49,6 +48,7 @@

import org.apache.geode.annotations.Immutable;
import org.apache.geode.annotations.internal.MakeNotStatic;
import org.apache.geode.unsafe.internal.sun.misc.Unsafe;

/**
* <p>
Expand Down Expand Up @@ -1961,13 +1961,9 @@ static <K> boolean checkInvariants(TreeNode<K> t) {
}

@Immutable
private static final sun.misc.Unsafe U;
private static final long LOCKSTATE;
static {
try {
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
U = (sun.misc.Unsafe) f.get(null);
Class<?> k = TreeBin.class;
LOCKSTATE = U.objectFieldOffset(k.getDeclaredField("lockState"));
} catch (Exception e) {
Expand Down Expand Up @@ -2287,7 +2283,7 @@ else if (cellsBusy == 0 && U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {

// Unsafe mechanics
@Immutable
private static final sun.misc.Unsafe U;
private static final Unsafe U = new Unsafe();
private static final long SIZECTL;
private static final long TRANSFERINDEX;
private static final long BASECOUNT;
Expand All @@ -2298,9 +2294,6 @@ else if (cellsBusy == 0 && U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {

static {
try {
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
U = (sun.misc.Unsafe) f.get(null);
Class<?> k = CompactConcurrentHashSet2.class;
SIZECTL = U.objectFieldOffset(k.getDeclaredField("sizeCtl"));
TRANSFERINDEX = U.objectFieldOffset(k.getDeclaredField("transferIndex"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.geode.annotations.Immutable;
import org.apache.geode.annotations.internal.MakeNotStatic;
import org.apache.geode.internal.JvmSizeUtils;
import org.apache.geode.pdx.internal.unsafe.UnsafeWrapper;
import org.apache.geode.unsafe.internal.sun.misc.Unsafe;

/**
* This class supports allocating and freeing large amounts of addressable memory (i.e. slabs). It
Expand All @@ -31,14 +31,14 @@
*/
public class AddressableMemoryManager {
@Immutable
private static final UnsafeWrapper unsafe;
private static final Unsafe unsafe;
private static final int ARRAY_BYTE_BASE_OFFSET;
private static final String reason;
static {
UnsafeWrapper tmp = null;
Unsafe tmp = null;
String tmpReason = null;
try {
tmp = new UnsafeWrapper();
tmp = new Unsafe();
} catch (RuntimeException ignore) {
tmpReason = ignore.toString();
} catch (Error ignore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.geode.annotations.Immutable;
import org.apache.geode.internal.Assert;
import org.apache.geode.internal.JvmSizeUtils;
import org.apache.geode.pdx.internal.unsafe.UnsafeWrapper;
import org.apache.geode.unsafe.internal.sun.misc.Unsafe;

/**
* Figure out the size of an object using reflection. This class does not follow any object
Expand All @@ -34,11 +34,11 @@ public class ReflectionSingleObjectSizer implements SingleObjectSizer {
public static final int OBJECT_SIZE = JvmSizeUtils.getObjectHeaderSize();

@Immutable
private static final UnsafeWrapper unsafe;
private static final Unsafe unsafe;
static {
UnsafeWrapper tmp = null;
Unsafe tmp = null;
try {
tmp = new UnsafeWrapper();
tmp = new Unsafe();
} catch (RuntimeException ignore) {
} catch (Error ignore) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import java.util.Map;

import jline.console.ConsoleReader;
import sun.misc.SignalHandler;

import org.apache.geode.internal.process.signal.AbstractSignalNotificationHandler;
import org.apache.geode.internal.process.signal.Signal;
import org.apache.geode.internal.process.signal.SignalEvent;
import org.apache.geode.management.internal.cli.shell.Gfsh;
import org.apache.geode.unsafe.internal.sun.misc.SignalHandler;

/**
* This class externalizes signal handling in order to make the GemFire build process a bit cleaner
Expand All @@ -41,19 +41,19 @@
public class GfshSignalHandler extends AbstractSignalNotificationHandler implements SignalHandler {

private final Map<Signal, SignalHandler> originalSignalHandlers =
Collections.synchronizedMap(new Hashtable<Signal, SignalHandler>(Signal.values().length));
Collections.synchronizedMap(new Hashtable<>(Signal.values().length));

public GfshSignalHandler() {
for (final Signal signal : Signal.values()) {
if (Signal.SIGINT.equals(signal)) {
originalSignalHandlers.put(signal,
sun.misc.Signal.handle(new sun.misc.Signal(signal.getName()), this));
originalSignalHandlers.put(signal, org.apache.geode.unsafe.internal.sun.misc.Signal
.handle(new org.apache.geode.unsafe.internal.sun.misc.Signal(signal.getName()), this));
}
}
}

@Override
public void handle(final sun.misc.Signal sig) {
public void handle(final org.apache.geode.unsafe.internal.sun.misc.Signal sig) {
notifyListeners(new SignalEvent(sig, Signal.valueOfName(sig.getName())));
try {
handleDefault(sig, Gfsh.getConsoleReader());
Expand All @@ -62,7 +62,8 @@ public void handle(final sun.misc.Signal sig) {
}
}

protected void handleDefault(final sun.misc.Signal sig, final ConsoleReader consoleReader)
protected void handleDefault(final org.apache.geode.unsafe.internal.sun.misc.Signal sig,
final ConsoleReader consoleReader)
throws IOException {
final Signal signal = Signal.valueOfName(sig.getName());
switch (signal) {
Expand All @@ -80,7 +81,7 @@ protected void handleDefault(final sun.misc.Signal sig, final ConsoleReader cons
}
}

protected SignalHandler getOriginalSignalHandler(final Signal signal) {
private SignalHandler getOriginalSignalHandler(final Signal signal) {
final SignalHandler handler = originalSignalHandlers.get(signal);
return (handler == SignalHandler.SIG_DFL || handler == SignalHandler.SIG_IGN ? null : handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import javax.management.ObjectName;
import javax.management.ReflectionException;

import com.sun.jmx.remote.security.MBeanServerFileAccessController;
import org.apache.geode.unsafe.internal.com.sun.jmx.remote.security.MBeanServerFileAccessController;

/**
* This class extends existing properties file based accessController in order to implement read
Expand Down
Loading

0 comments on commit 7efc2cd

Please sign in to comment.