From df876d2e0f4a3d4b99249ae03f901adcb9175c36 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Wed, 28 Oct 2015 20:24:12 +0100 Subject: [PATCH] [performance] Remove synthetic access$ methods in transport package Java compiler must generate synthetic access methods for private methods and fields of the enclosing class if they are accessed from inner classes and vice versa. While invisible in the code, those synthetic access methods exist in the bytecode and seem to produce some extra execution overhead at runtime (compared with the direct access to this fields or methods), see https://git.eclipse.org/r/58948/. By removing the "private" access modifier from affected methods and fields we help compiler to avoid generation of synthetic access methods and hope to improve execution performance. To validate changes, one can either use javap or use Bytecode Outline plugin in Eclipse. In both cases one should look for "synthetic access$" methods at the end of the class and inner class files in question - there should be none. NB: don't mix this "synthetic access$" methods up with "public synthetic bridge" methods generated to allow generic method override return types. Change-Id: I0ebaeb2bc454cd8051b901addb102c1a6688688b Signed-off-by: Andrey Loskutov --- .../org/eclipse/jgit/transport/AmazonS3.java | 12 ++++++------ .../src/org/eclipse/jgit/transport/Daemon.java | 8 ++++---- .../eclipse/jgit/transport/JschSession.java | 8 ++++---- .../org/eclipse/jgit/transport/PackParser.java | 8 ++++---- .../jgit/transport/PushCertificateStore.java | 18 +++++++++--------- .../eclipse/jgit/transport/TestProtocol.java | 12 ++++++------ .../jgit/transport/TrackingRefUpdate.java | 10 +++++----- .../eclipse/jgit/transport/TransferConfig.java | 4 ++-- .../jgit/transport/TransportAmazonS3.java | 4 ++-- .../eclipse/jgit/transport/TransportHttp.java | 6 +++--- .../jgit/transport/WalkFetchConnection.java | 10 +++++----- .../jgit/transport/WalkPushConnection.java | 2 +- 12 files changed, 51 insertions(+), 51 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index 0c8ee5d4b..4069a6453 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -175,7 +175,7 @@ public class AmazonS3 { private final String acl; /** Maximum number of times to try an operation. */ - private final int maxAttempts; + final int maxAttempts; /** Encryption algorithm, may be a null instance that provides pass-through. */ private final WalkEncryption encryption; @@ -483,7 +483,7 @@ public class AmazonS3 { return encryption.encrypt(new DigestOutputStream(buffer, md5)); } - private void putImpl(final String bucket, final String key, + void putImpl(final String bucket, final String key, final byte[] csum, final TemporaryBuffer buf, ProgressMonitor monitor, String monitorTask) throws IOException { if (monitor == null) @@ -522,7 +522,7 @@ public class AmazonS3 { throw maxAttempts(JGitText.get().s3ActionWriting, key); } - private IOException error(final String action, final String key, + IOException error(final String action, final String key, final HttpURLConnection c) throws IOException { final IOException err = new IOException(MessageFormat.format( JGitText.get().amazonS3ActionFailed, action, key, @@ -547,7 +547,7 @@ public class AmazonS3 { return err; } - private IOException maxAttempts(final String action, final String key) { + IOException maxAttempts(final String action, final String key) { return new IOException(MessageFormat.format( JGitText.get().amazonS3ActionFailedGivingUp, action, key, Integer.valueOf(maxAttempts))); @@ -559,7 +559,7 @@ public class AmazonS3 { return open(method, bucket, key, noArgs); } - private HttpURLConnection open(final String method, final String bucket, + HttpURLConnection open(final String method, final String bucket, final String key, final Map args) throws IOException { final StringBuilder urlstr = new StringBuilder(); @@ -596,7 +596,7 @@ public class AmazonS3 { return c; } - private void authorize(final HttpURLConnection c) throws IOException { + void authorize(final HttpURLConnection c) throws IOException { final Map> reqHdr = c.getRequestProperties(); final SortedMap sigHdr = new TreeMap(); for (final Map.Entry> entry : reqHdr.entrySet()) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java index 03f7c7283..d9e0b937e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java @@ -79,7 +79,7 @@ public class Daemon { private boolean run; - private Thread acceptThread; + Thread acceptThread; private int timeout; @@ -87,9 +87,9 @@ public class Daemon { private volatile RepositoryResolver repositoryResolver; - private volatile UploadPackFactory uploadPackFactory; + volatile UploadPackFactory uploadPackFactory; - private volatile ReceivePackFactory receivePackFactory; + volatile ReceivePackFactory receivePackFactory; /** Configure a daemon to listen on any available network port. */ public Daemon() { @@ -326,7 +326,7 @@ public class Daemon { } } - private void startClient(final Socket s) { + void startClient(final Socket s) { final DaemonClient dc = new DaemonClient(this); final SocketAddress peer = s.getRemoteSocketAddress(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java index b4a09020b..85109a5bf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java @@ -71,8 +71,8 @@ import com.jcraft.jsch.Session; * to the constructor. */ public class JschSession implements RemoteSession { - private final Session sock; - private final URIish uri; + final Session sock; + final URIish uri; /** * Create a new session object by passing the real Jsch session and the URI @@ -119,7 +119,7 @@ public class JschSession implements RemoteSession { private class JschProcess extends Process { private ChannelExec channel; - private final int timeout; + final int timeout; private InputStream inputStream; @@ -141,7 +141,7 @@ public class JschSession implements RemoteSession { * @throws IOException * on problems opening streams */ - private JschProcess(final String commandName, int tms) + JschProcess(final String commandName, int tms) throws TransportException, IOException { timeout = tms; try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java index 918df94de..6e5fc9f00 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java @@ -122,14 +122,14 @@ public abstract class PackParser { private InputStream in; - private byte[] buf; + byte[] buf; /** Position in the input stream of {@code buf[0]}. */ private long bBase; private int bOffset; - private int bAvail; + int bAvail; private ObjectChecker objCheck; @@ -1141,13 +1141,13 @@ public abstract class PackParser { } // Consume cnt bytes from the buffer. - private void use(final int cnt) { + void use(final int cnt) { bOffset += cnt; bAvail -= cnt; } // Ensure at least need bytes are available in in {@link #buf}. - private int fill(final Source src, final int need) throws IOException { + int fill(final Source src, final int need) throws IOException { while (bAvail < need) { int next = bOffset + bAvail; int free = buf.length - next; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java index d8672d5a2..8947f2779 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java @@ -107,11 +107,11 @@ public class PushCertificateStore implements AutoCloseable { Constants.R_REFS + "meta/push-certs"; //$NON-NLS-1$ private static class PendingCert { - private PushCertificate cert; - private PersonIdent ident; - private Collection matching; + PushCertificate cert; + PersonIdent ident; + Collection matching; - private PendingCert(PushCertificate cert, PersonIdent ident, + PendingCert(PushCertificate cert, PersonIdent ident, Collection matching) { this.cert = cert; this.ident = ident; @@ -121,8 +121,8 @@ public class PushCertificateStore implements AutoCloseable { private final Repository db; private final List pending; - private ObjectReader reader; - private RevCommit commit; + ObjectReader reader; + RevCommit commit; /** * Create a new store backed by the given repository. @@ -270,7 +270,7 @@ public class PushCertificateStore implements AutoCloseable { }; } - private void load() throws IOException { + void load() throws IOException { close(); reader = db.newObjectReader(); Ref ref = db.getRefDatabase().exactRef(REF_NAME); @@ -283,7 +283,7 @@ public class PushCertificateStore implements AutoCloseable { } } - private static PushCertificate read(TreeWalk tw) throws IOException { + static PushCertificate read(TreeWalk tw) throws IOException { if (tw == null || (tw.getRawMode(0) & TYPE_FILE) != TYPE_FILE) { return null; } @@ -532,7 +532,7 @@ public class PushCertificateStore implements AutoCloseable { return TreeWalk.forPath(reader, pathName(refName), commit.getTree()); } - private static String pathName(String refName) { + static String pathName(String refName) { return refName + "@{cert}"; //$NON-NLS-1$ } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TestProtocol.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TestProtocol.java index 524301050..5fd2f84b7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TestProtocol.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TestProtocol.java @@ -78,17 +78,17 @@ public class TestProtocol extends TransportProtocol { private static final String SCHEME = "test"; //$NON-NLS-1$ private class Handle { - private final C req; - private final Repository remote; + final C req; + final Repository remote; - private Handle(C req, Repository remote) { + Handle(C req, Repository remote) { this.req = req; this.remote = remote; } } - private final UploadPackFactory uploadPackFactory; - private final ReceivePackFactory receivePackFactory; + final UploadPackFactory uploadPackFactory; + final ReceivePackFactory receivePackFactory; private final HashMap handles; /** @@ -165,7 +165,7 @@ public class TestProtocol extends TransportProtocol { private class TransportInternal extends Transport implements PackTransport { private final Handle handle; - private TransportInternal(Repository local, URIish uri, Handle handle) { + TransportInternal(Repository local, URIish uri, Handle handle) { super(local, uri); this.handle = handle; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TrackingRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TrackingRefUpdate.java index 1ef3fbf62..5aae5ea21 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TrackingRefUpdate.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TrackingRefUpdate.java @@ -52,10 +52,10 @@ import org.eclipse.jgit.lib.RefUpdate; /** Update of a locally stored tracking branch. */ public class TrackingRefUpdate { private final String remoteName; - private final String localName; - private boolean forceUpdate; - private ObjectId oldObjectId; - private ObjectId newObjectId; + final String localName; + boolean forceUpdate; + ObjectId oldObjectId; + ObjectId newObjectId; private RefUpdate.Result result; private ReceiveCommand cmd; @@ -142,7 +142,7 @@ public class TrackingRefUpdate { } final class Command extends ReceiveCommand { - private Command() { + Command() { super(oldObjectId, newObjectId, localName); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java index f4de82147..f0c513427 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java @@ -72,13 +72,13 @@ public class TransferConfig { private final boolean safeForMacOS; private final boolean allowTipSha1InWant; private final boolean allowReachableSha1InWant; - private final String[] hideRefs; + final String[] hideRefs; TransferConfig(final Repository db) { this(db.getConfig()); } - private TransferConfig(final Config rc) { + TransferConfig(final Config rc) { checkReceivedObjects = rc.getBoolean( "fetch", "fsckobjects", //$NON-NLS-1$ //$NON-NLS-2$ rc.getBoolean("transfer", "fsckobjects", false)); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java index 745cdb72d..7729c11ff 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java @@ -125,10 +125,10 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { }; /** User information necessary to connect to S3. */ - private final AmazonS3 s3; + final AmazonS3 s3; /** Bucket the remote repository is stored in. */ - private final String bucket; + final String bucket; /** * Key prefix which all objects related to the repository start with. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java index b23771e95..594827886 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -218,16 +218,16 @@ public class TransportHttp extends HttpTransport implements WalkTransport, sslVerify = rc.getBoolean("http", "sslVerify", true); //$NON-NLS-1$ //$NON-NLS-2$ } - private HttpConfig() { + HttpConfig() { this(new Config()); } } - private final URL baseUrl; + final URL baseUrl; private final URL objectsUrl; - private final HttpConfig http; + final HttpConfig http; private final ProxySelector proxySelector; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java index dc9dee55a..1c6b8b736 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java @@ -115,10 +115,10 @@ import org.eclipse.jgit.util.FileUtils; */ class WalkFetchConnection extends BaseFetchConnection { /** The repository this transport fetches into, or pushes out of. */ - private final Repository local; + final Repository local; /** If not null the validator for received objects. */ - private final ObjectChecker objCheck; + final ObjectChecker objCheck; /** * List of all remote repositories we may need to get objects out of. @@ -180,12 +180,12 @@ class WalkFetchConnection extends BaseFetchConnection { */ private final HashMap> fetchErrors; - private String lockMessage; + String lockMessage; - private final List packLocks; + final List packLocks; /** Inserter to write objects onto {@link #local}. */ - private final ObjectInserter inserter; + final ObjectInserter inserter; /** Inserter to read objects from {@link #local}. */ private final ObjectReader reader; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java index deecb8e15..4eaf3f9d8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java @@ -103,7 +103,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { private final URIish uri; /** Database connection to the remote repository. */ - private final WalkRemoteObjectDatabase dest; + final WalkRemoteObjectDatabase dest; /** The configured transport we were constructed by. */ private final Transport transport;