Skip to content

Commit 93f4cd0

Browse files
committed
Move SizeEstimator out of util
1 parent e21c1f4 commit 93f4cd0

File tree

12 files changed

+29
-28
lines changed

12 files changed

+29
-28
lines changed

core/src/main/scala/org/apache/spark/util/SizeEstimator.scala renamed to core/src/main/scala/org/apache/spark/SizeEstimator.scala

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.spark.util
18+
package org.apache.spark
1919

2020
import java.lang.management.ManagementFactory
2121
import java.lang.reflect.{Field, Modifier}
@@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap
2424
import scala.collection.mutable.ArrayBuffer
2525
import scala.runtime.ScalaRunTime
2626

27-
import org.apache.spark.Logging
27+
import org.apache.spark.annotation.DeveloperApi
2828
import org.apache.spark.util.collection.OpenHashSet
2929

3030

@@ -35,7 +35,8 @@ import org.apache.spark.util.collection.OpenHashSet
3535
* Based on the following JavaWorld article:
3636
* http://www.javaworld.com/javaworld/javaqa/2003-12/02-qa-1226-sizeof.html
3737
*/
38-
private[spark] object SizeEstimator extends Logging {
38+
@DeveloperApi
39+
object SizeEstimator extends Logging {
3940

4041
// Sizes of primitive types
4142
private val BYTE_SIZE = 1
@@ -155,6 +156,18 @@ private[spark] object SizeEstimator extends Logging {
155156
val shellSize: Long,
156157
val pointerFields: List[Field]) {}
157158

159+
/**
160+
* :: DeveloperApi ::
161+
* Estimate the number of bytes that the given object takes up on the JVM heap. The estimate
162+
* includes space taken up by objects referenced by the given object, their references, and so on
163+
* and so forth.
164+
*
165+
* This is useful for determining the amount of heap space a broadcast variable will occupy on
166+
* each executor or the amount of space each object will take when caching objects in
167+
* deserialized form. This is not the same as the serialized size of the object, which will
168+
* typically be much smaller.
169+
*/
170+
@DeveloperApi
158171
def estimate(obj: AnyRef): Long = estimate(obj, new IdentityHashMap[AnyRef, AnyRef])
159172

160173
private def estimate(obj: AnyRef, visited: IdentityHashMap[AnyRef, AnyRef]): Long = {

core/src/main/scala/org/apache/spark/SparkContext.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,20 +2263,6 @@ object SparkContext extends Logging {
22632263
*/
22642264
def jarOfObject(obj: AnyRef): Option[String] = jarOfClass(obj.getClass)
22652265

2266-
/**
2267-
* :: DeveloperApi ::
2268-
* Estimate the number of bytes that the given object takes up on the JVM heap. The estimate
2269-
* includes space taken up by objects referenced by the given object, their references, and so on
2270-
* and so forth.
2271-
*
2272-
* This is useful for determining the amount of heap space a broadcast variable will occupy on
2273-
* each executor or the amount of space each object will take when caching objects in
2274-
* deserialized form. This is not the same as the serialized size of the object, which will
2275-
* typically be much smaller.
2276-
*/
2277-
@DeveloperApi
2278-
def estimateSizeOf(obj: AnyRef): Long = SizeEstimator.estimate(obj)
2279-
22802266
/**
22812267
* Creates a modified version of a SparkConf with the parameters that can be passed separately
22822268
* to SparkContext, to make it easier to write SparkContext's constructors. This ignores

core/src/main/scala/org/apache/spark/storage/MemoryStore.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import java.util.LinkedHashMap
2323
import scala.collection.mutable
2424
import scala.collection.mutable.ArrayBuffer
2525

26-
import org.apache.spark.util.{SizeEstimator, Utils}
26+
import org.apache.spark.SizeEstimator
27+
import org.apache.spark.util.Utils
2728
import org.apache.spark.util.collection.SizeTrackingVector
2829

2930
private case class MemoryEntry(value: Any, size: Long, deserialized: Boolean)

core/src/main/scala/org/apache/spark/util/collection/SizeTracker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.apache.spark.util.collection
1919

2020
import scala.collection.mutable
2121

22-
import org.apache.spark.util.SizeEstimator
22+
import org.apache.spark.SizeEstimator
2323

2424
/**
2525
* A general interface for collections to keep track of their estimated sizes in bytes.

core/src/test/scala/org/apache/spark/util/SizeEstimatorSuite.scala renamed to core/src/test/scala/org/apache/spark/SizeEstimatorSuite.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.spark.util
18+
package org.apache.spark
1919

2020
import scala.collection.mutable.ArrayBuffer
2121

2222
import org.scalatest.{BeforeAndAfterEach, BeforeAndAfterAll, FunSuite, PrivateMethodTester}
23+
import org.apache.spark.util.ResetSystemProperties
2324

2425
class DummyClass1 {}
2526

core/src/test/scala/org/apache/spark/storage/BlockManagerSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import org.scalatest.concurrent.Eventually._
3131
import org.scalatest.concurrent.Timeouts._
3232

3333
import org.apache.spark.rpc.RpcEnv
34-
import org.apache.spark.{MapOutputTrackerMaster, SparkConf, SparkContext, SecurityManager}
34+
import org.apache.spark._
3535
import org.apache.spark.executor.DataReadMethod
3636
import org.apache.spark.network.nio.NioBlockTransferService
3737
import org.apache.spark.scheduler.LiveListenerBus

core/src/test/scala/org/apache/spark/util/collection/OpenHashMapSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.collection.mutable.HashSet
2222
import org.scalatest.FunSuite
2323
import org.scalatest.Matchers
2424

25-
import org.apache.spark.util.SizeEstimator
25+
import org.apache.spark.SizeEstimator
2626

2727
class OpenHashMapSuite extends FunSuite with Matchers {
2828

core/src/test/scala/org/apache/spark/util/collection/OpenHashSetSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.spark.util.collection
2020
import org.scalatest.FunSuite
2121
import org.scalatest.Matchers
2222

23-
import org.apache.spark.util.SizeEstimator
23+
import org.apache.spark.SizeEstimator
2424

2525
class OpenHashSetSuite extends FunSuite with Matchers {
2626

core/src/test/scala/org/apache/spark/util/collection/PrimitiveKeyOpenHashMapSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.collection.mutable.HashSet
2222
import org.scalatest.FunSuite
2323
import org.scalatest.Matchers
2424

25-
import org.apache.spark.util.SizeEstimator
25+
import org.apache.spark.SizeEstimator
2626

2727
class PrimitiveKeyOpenHashMapSuite extends FunSuite with Matchers {
2828

core/src/test/scala/org/apache/spark/util/collection/PrimitiveVectorSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.apache.spark.util.collection
1919

2020
import org.scalatest.FunSuite
2121

22-
import org.apache.spark.util.SizeEstimator
22+
import org.apache.spark.SizeEstimator
2323

2424
class PrimitiveVectorSuite extends FunSuite {
2525

0 commit comments

Comments
 (0)