You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/04/12 19:43:06 UTC

[16/50] [abbrv] incubator-geode git commit: GEODE-1177: Adding a few more classes to exclude from object sizing

GEODE-1177: Adding a few more classes to exclude from object sizing

This is not a complete fix for the http session management problem, but
this is a safety catch we should probably have in the product to avoid
following references into InternalDistributedSystem, Classloaders, or
Loggers when computing the size of a user's object.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/e0c20de1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/e0c20de1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/e0c20de1

Branch: refs/heads/feature/GEODE-1162
Commit: e0c20de1645d65bd67eb61350c2ad474b341998c
Parents: 4c2d309
Author: Dan Smith <up...@apache.org>
Authored: Tue Apr 5 13:30:44 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Thu Apr 7 14:34:20 2016 -0700

----------------------------------------------------------------------
 .../internal/size/ReflectionObjectSizer.java    |  9 ++-
 .../size/ReflectionObjectSizerJUnitTest.java    | 71 ++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e0c20de1/geode-core/src/main/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizer.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizer.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizer.java
index 04961b6..36443da 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizer.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizer.java
@@ -24,9 +24,12 @@ import com.gemstone.gemfire.InternalGemFireError;
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.util.ObjectSizer;
+import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
 import com.gemstone.gemfire.internal.cache.PlaceHolderDiskRegion;
 import com.gemstone.gemfire.internal.size.ObjectGraphSizer.ObjectFilter;
 
+import org.apache.logging.log4j.Logger;
+
 /**
  * An implementation of {@link ObjectSizer} that calculates an accurate, in
  * memory size of for each object that it sizes. This is the slowest method of
@@ -52,9 +55,13 @@ public class ReflectionObjectSizer implements ObjectSizer, Serializable {
       //Protect the user from a couple of pitfalls. If their object
       //has a link to a region or cache, we don't want to size the whole thing.
       if (object instanceof Region || object instanceof Cache
-          || object instanceof PlaceHolderDiskRegion) {
+          || object instanceof PlaceHolderDiskRegion
+          || object instanceof InternalDistributedSystem
+          || object instanceof ClassLoader
+          || object instanceof Logger) {
         return false;
       }
+
       return true;
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e0c20de1/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizerJUnitTest.java
new file mode 100644
index 0000000..4489433
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizerJUnitTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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 com.gemstone.gemfire.internal.size;
+
+import static org.junit.Assert.*;
+
+import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import io.codearte.catchexception.shade.mockito.Mockito;
+
+@Category(UnitTest.class)
+public class ReflectionObjectSizerJUnitTest {
+
+  @Test
+  public void skipsSizingDistributedSystem() {
+
+    Object referenceObject = Mockito.mock(InternalDistributedSystem.class);
+    checkSizeDoesNotChange(referenceObject);
+  }
+
+  @Test
+  public void skipsSizingClassLoader() {
+
+    checkSizeDoesNotChange(Thread.currentThread().getContextClassLoader());
+  }
+
+  @Test
+  public void skipsSizingLogger() {
+    checkSizeDoesNotChange(LogService.getLogger());
+  }
+
+  private void checkSizeDoesNotChange(final Object referenceObject) {
+    final ReflectionObjectSizer sizer = ReflectionObjectSizer.getInstance();
+    final TestObject nullReference = new TestObject(null);
+    int sizeWithoutReference = sizer.sizeof(nullReference);
+    final TestObject distributedSystemReference = new TestObject(referenceObject);
+    final TestObject stringReference = new TestObject("hello");
+
+    assertEquals(sizeWithoutReference, sizer.sizeof(distributedSystemReference));
+    assertNotEquals(sizeWithoutReference, sizer.sizeof(stringReference));
+  }
+
+  public class TestObject {
+
+    public TestObject(final Object reference) {
+      this.reference = reference;
+    }
+
+    Object reference = null;
+  }
+
+}