Add Class::IsFinalizable and Object::AddFinalizerReference.

Also correctly set the special bit in Class' flags.

We need compiler support before I can go further.

Change-Id: Ib7a637d7140a6f8c416635738d4d0b57c17ad628
diff --git a/src/class_linker_test.cc b/src/class_linker_test.cc
index 18a3f92..8be1b90 100644
--- a/src/class_linker_test.cc
+++ b/src/class_linker_test.cc
@@ -969,4 +969,37 @@
   EXPECT_EQ(init, clinit->GetDexCacheInitializedStaticStorage()->Get(type_idx));
 }
 
+TEST_F(ClassLinkerTest, FinalizableBit) {
+  Class* c;
+
+  // Object has a finalize method, but we know it's empty.
+  c = class_linker_->FindSystemClass("Ljava/lang/Object;");
+  EXPECT_FALSE(c->IsFinalizable());
+
+  // Enum has a finalize method to prevent its subclasses from implementing one.
+  c = class_linker_->FindSystemClass("Ljava/lang/Enum;");
+  EXPECT_FALSE(c->IsFinalizable());
+
+  // RoundingMode is an enum.
+  c = class_linker_->FindSystemClass("Ljava/math/RoundingMode;");
+  EXPECT_FALSE(c->IsFinalizable());
+
+  // RandomAccessFile extends Object and overrides finalize.
+  c = class_linker_->FindSystemClass("Ljava/io/RandomAccessFile;");
+  EXPECT_TRUE(c->IsFinalizable());
+
+  // FileInputStream is finalizable and extends InputStream which isn't.
+  c = class_linker_->FindSystemClass("Ljava/io/InputStream;");
+  EXPECT_FALSE(c->IsFinalizable());
+  c = class_linker_->FindSystemClass("Ljava/io/FileInputStream;");
+  EXPECT_TRUE(c->IsFinalizable());
+
+  // ScheduledThreadPoolExecutor doesn't have a finalize method but
+  // extends ThreadPoolExecutor which does.
+  c = class_linker_->FindSystemClass("Ljava/util/concurrent/ThreadPoolExecutor;");
+  EXPECT_TRUE(c->IsFinalizable());
+  c = class_linker_->FindSystemClass("Ljava/util/concurrent/ScheduledThreadPoolExecutor;");
+  EXPECT_TRUE(c->IsFinalizable());
+}
+
 }  // namespace art