Skip to content

Commit 2e1a906

Browse files
committed
Revert "Move SizeEstimator out of util"
This reverts commit 93f4cd0.
1 parent 93f4cd0 commit 2e1a906

File tree

12 files changed

+28
-29
lines changed

12 files changed

+28
-29
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,20 @@ 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+
22662280
/**
22672281
* Creates a modified version of a SparkConf with the parameters that can be passed separately
22682282
* 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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import java.util.LinkedHashMap
2323
import scala.collection.mutable
2424
import scala.collection.mutable.ArrayBuffer
2525

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

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

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

Lines changed: 3 additions & 16 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
18+
package org.apache.spark.util
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.annotation.DeveloperApi
27+
import org.apache.spark.Logging
2828
import org.apache.spark.util.collection.OpenHashSet
2929

3030

@@ -35,8 +35,7 @@ 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-
@DeveloperApi
39-
object SizeEstimator extends Logging {
38+
private[spark] object SizeEstimator extends Logging {
4039

4140
// Sizes of primitive types
4241
private val BYTE_SIZE = 1
@@ -156,18 +155,6 @@ object SizeEstimator extends Logging {
156155
val shellSize: Long,
157156
val pointerFields: List[Field]) {}
158157

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
171158
def estimate(obj: AnyRef): Long = estimate(obj, new IdentityHashMap[AnyRef, AnyRef])
172159

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

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.SizeEstimator
22+
import org.apache.spark.util.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/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._
34+
import org.apache.spark.{MapOutputTrackerMaster, SparkConf, SparkContext, SecurityManager}
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/SizeEstimatorSuite.scala renamed to core/src/test/scala/org/apache/spark/util/SizeEstimatorSuite.scala

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

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

2020
import scala.collection.mutable.ArrayBuffer
2121

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

2524
class DummyClass1 {}
2625

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.SizeEstimator
25+
import org.apache.spark.util.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.SizeEstimator
23+
import org.apache.spark.util.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.SizeEstimator
25+
import org.apache.spark.util.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.SizeEstimator
22+
import org.apache.spark.util.SizeEstimator
2323

2424
class PrimitiveVectorSuite extends FunSuite {
2525

0 commit comments

Comments
 (0)