Push Closure into only use in thread_pool.h.
Remove StringFile and NullFile that existed purely for a test.
Change-Id: I329892d5e1f5f017caeb3d60600f803a74114fc1
runtime/base/stringprintf_test.cc \
runtime/base/timing_logger_test.cc \
runtime/base/unix_file/fd_file_test.cc \
- runtime/base/unix_file/null_file_test.cc \
- runtime/base/unix_file/random_access_file_utils_test.cc \
- runtime/base/unix_file/string_file_test.cc \
runtime/class_linker_test.cc \
runtime/dex_file_test.cc \
runtime/dex_file_verifier_test.cc \
base/stringprintf.cc \
base/timing_logger.cc \
base/unix_file/fd_file.cc \
- base/unix_file/null_file.cc \
base/unix_file/random_access_file_utils.cc \
- base/unix_file/string_file.cc \
check_jni.cc \
class_linker.cc \
common_throws.cc \
+++ /dev/null
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-#include "base/unix_file/null_file.h"
-#include <errno.h>
-
-namespace unix_file {
-
-NullFile::NullFile() {
-}
-
-NullFile::~NullFile() {
-}
-
-int NullFile::Close() {
- return 0;
-}
-
-int NullFile::Flush() {
- return 0;
-}
-
-int64_t NullFile::Read(char* buf ATTRIBUTE_UNUSED, int64_t byte_count ATTRIBUTE_UNUSED,
- int64_t offset) const {
- if (offset < 0) {
- return -EINVAL;
- }
- return 0;
-}
-
-int NullFile::SetLength(int64_t new_length) {
- if (new_length < 0) {
- return -EINVAL;
- }
- return 0;
-}
-
-int64_t NullFile::GetLength() const {
- return 0;
-}
-
-int64_t NullFile::Write(const char* buf ATTRIBUTE_UNUSED, int64_t byte_count ATTRIBUTE_UNUSED,
- int64_t offset) {
- if (offset < 0) {
- return -EINVAL;
- }
- return byte_count;
-}
-
-} // namespace unix_file
+++ /dev/null
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-#ifndef ART_RUNTIME_BASE_UNIX_FILE_NULL_FILE_H_
-#define ART_RUNTIME_BASE_UNIX_FILE_NULL_FILE_H_
-
-#include "base/unix_file/random_access_file.h"
-#include "base/macros.h"
-
-namespace unix_file {
-
-// A RandomAccessFile implementation equivalent to /dev/null. Writes are
-// discarded, and there's no data to be read. Callers could use FdFile in
-// conjunction with /dev/null, but that's not portable and costs a file
-// descriptor. NullFile is "free".
-//
-// Thread safe.
-class NullFile : public RandomAccessFile {
- public:
- NullFile();
- virtual ~NullFile();
-
- // RandomAccessFile API.
- virtual int Close();
- virtual int Flush();
- virtual int64_t Read(char* buf, int64_t byte_count, int64_t offset) const;
- virtual int SetLength(int64_t new_length);
- virtual int64_t GetLength() const;
- virtual int64_t Write(const char* buf, int64_t byte_count, int64_t offset);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(NullFile);
-};
-
-} // namespace unix_file
-
-#endif // ART_RUNTIME_BASE_UNIX_FILE_NULL_FILE_H_
+++ /dev/null
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-#include "base/unix_file/null_file.h"
-
-#include <errno.h>
-
-#include "gtest/gtest.h"
-
-namespace unix_file {
-
-class NullFileTest : public testing::Test { };
-
-TEST_F(NullFileTest, Read) {
- NullFile f;
- char buf[256];
- // You can't read a negative number of bytes...
- ASSERT_EQ(-EINVAL, f.Read(buf, 0, -1));
- // ...but everything else is fine (though you'll get no data).
- ASSERT_EQ(0, f.Read(buf, 128, 0));
- ASSERT_EQ(0, f.Read(buf, 128, 128));
-}
-
-TEST_F(NullFileTest, SetLength) {
- NullFile f;
- // You can't set a negative length...
- ASSERT_EQ(-EINVAL, f.SetLength(-1));
- // ...but everything else is fine.
- ASSERT_EQ(0, f.SetLength(0));
- ASSERT_EQ(0, f.SetLength(128));
-}
-
-TEST_F(NullFileTest, GetLength) {
- const std::string content("hello");
- NullFile f;
- // The length is always 0.
- ASSERT_EQ(0, f.GetLength());
- ASSERT_EQ(content.size(), static_cast<uint64_t>(f.Write(content.data(), content.size(), 0)));
- ASSERT_EQ(0, f.GetLength());
-}
-
-TEST_F(NullFileTest, Write) {
- const std::string content("hello");
- NullFile f;
- // You can't write at a negative offset...
- ASSERT_EQ(-EINVAL, f.Write(content.data(), content.size(), -128));
- // But you can write anywhere else...
- ASSERT_EQ(content.size(), static_cast<uint64_t>(f.Write(content.data(), content.size(), 0)));
- ASSERT_EQ(content.size(), static_cast<uint64_t>(f.Write(content.data(), content.size(), 128)));
- // ...though the file will remain empty.
- ASSERT_EQ(0, f.GetLength());
-}
-
-} // namespace unix_file
+++ /dev/null
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-#include "base/unix_file/random_access_file_utils.h"
-#include "base/unix_file/fd_file.h"
-#include "base/unix_file/string_file.h"
-#include "gtest/gtest.h"
-
-namespace unix_file {
-
-class RandomAccessFileUtilsTest : public testing::Test { };
-
-TEST_F(RandomAccessFileUtilsTest, CopyFile) {
- StringFile src;
- StringFile dst;
-
- const std::string content("hello");
- src.Assign(content);
- ASSERT_EQ(src.ToStringPiece(), content);
- ASSERT_EQ(dst.ToStringPiece(), "");
-
- ASSERT_TRUE(CopyFile(src, &dst));
- ASSERT_EQ(src.ToStringPiece(), dst.ToStringPiece());
-}
-
-TEST_F(RandomAccessFileUtilsTest, BadSrc) {
- FdFile src(-1, false);
- StringFile dst;
- ASSERT_FALSE(CopyFile(src, &dst));
-}
-
-TEST_F(RandomAccessFileUtilsTest, BadDst) {
- StringFile src;
- FdFile dst(-1, false);
-
- // We need some source content to trigger a write.
- // Copying an empty file is a no-op.
- src.Assign("hello");
-
- ASSERT_FALSE(CopyFile(src, &dst));
-}
-
-} // namespace unix_file
+++ /dev/null
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-#include "base/unix_file/string_file.h"
-#include <errno.h>
-#include <algorithm>
-#include "base/logging.h"
-
-namespace unix_file {
-
-StringFile::StringFile() {
-}
-
-StringFile::~StringFile() {
-}
-
-int StringFile::Close() {
- return 0;
-}
-
-int StringFile::Flush() {
- return 0;
-}
-
-int64_t StringFile::Read(char *buf, int64_t byte_count, int64_t offset) const {
- CHECK(buf);
- CHECK_GE(byte_count, 0);
-
- if (offset < 0) {
- return -EINVAL;
- }
-
- const int64_t available_bytes = std::min(byte_count, GetLength() - offset);
- if (available_bytes < 0) {
- return 0; // Not an error, but nothing for us to do, either.
- }
- memcpy(buf, data_.data() + offset, available_bytes);
- return available_bytes;
-}
-
-int StringFile::SetLength(int64_t new_length) {
- if (new_length < 0) {
- return -EINVAL;
- }
- data_.resize(new_length);
- return 0;
-}
-
-int64_t StringFile::GetLength() const {
- return data_.size();
-}
-
-int64_t StringFile::Write(const char *buf, int64_t byte_count, int64_t offset) {
- CHECK(buf);
- CHECK_GE(byte_count, 0);
-
- if (offset < 0) {
- return -EINVAL;
- }
-
- if (byte_count == 0) {
- return 0;
- }
-
- // FUSE seems happy to allow writes past the end. (I'd guess it doesn't
- // synthesize a write of zero bytes so that we're free to implement sparse
- // files.) GNU as(1) seems to require such writes. Those files are small.
- const int64_t bytes_past_end = offset - GetLength();
- if (bytes_past_end > 0) {
- data_.append(bytes_past_end, '\0');
- }
-
- data_.replace(offset, byte_count, buf, byte_count);
- return byte_count;
-}
-
-void StringFile::Assign(const art::StringPiece &new_data) {
- data_.assign(new_data.data(), new_data.size());
-}
-
-const art::StringPiece StringFile::ToStringPiece() const {
- return data_;
-}
-
-} // namespace unix_file
+++ /dev/null
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-#ifndef ART_RUNTIME_BASE_UNIX_FILE_STRING_FILE_H_
-#define ART_RUNTIME_BASE_UNIX_FILE_STRING_FILE_H_
-
-#include <stdint.h>
-
-#include <string>
-
-#include "base/macros.h"
-#include "base/stringpiece.h"
-#include "base/unix_file/random_access_file.h"
-
-namespace unix_file {
-
-// A RandomAccessFile implementation backed by a std::string. (That is, all data is
-// kept in memory.)
-//
-// Not thread safe.
-class StringFile : public RandomAccessFile {
- public:
- StringFile();
- virtual ~StringFile();
-
- // RandomAccessFile API.
- virtual int Close();
- virtual int Flush();
- virtual int64_t Read(char* buf, int64_t byte_count, int64_t offset) const;
- virtual int SetLength(int64_t new_length);
- virtual int64_t GetLength() const;
- virtual int64_t Write(const char* buf, int64_t byte_count, int64_t offset);
-
- // Bonus API.
- void Assign(const art::StringPiece& new_data);
- const art::StringPiece ToStringPiece() const;
-
- private:
- std::string data_;
-
- DISALLOW_COPY_AND_ASSIGN(StringFile);
-};
-
-} // namespace unix_file
-
-#endif // ART_RUNTIME_BASE_UNIX_FILE_STRING_FILE_H_
+++ /dev/null
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-#include "base/unix_file/string_file.h"
-#include "base/unix_file/random_access_file_test.h"
-#include "gtest/gtest.h"
-
-namespace unix_file {
-
-class StringFileTest : public RandomAccessFileTest {
- protected:
- virtual RandomAccessFile* MakeTestFile() {
- return new StringFile;
- }
-};
-
-TEST_F(StringFileTest, Read) {
- TestRead();
-}
-
-TEST_F(StringFileTest, SetLength) {
- TestSetLength();
-}
-
-TEST_F(StringFileTest, Write) {
- TestWrite();
-}
-
-} // namespace unix_file
+++ /dev/null
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-#ifndef ART_RUNTIME_CLOSURE_H_
-#define ART_RUNTIME_CLOSURE_H_
-
-namespace art {
-
-class Thread;
-
-class Closure {
- public:
- virtual ~Closure() { }
- virtual void Run(Thread* self) = 0;
-};
-
-} // namespace art
-
-#endif // ART_RUNTIME_CLOSURE_H_
+++ /dev/null
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-#ifndef ART_RUNTIME_STRUTIL_H_
-#define ART_RUNTIME_STRUTIL_H_
-
-#include <string.h>
-
-namespace art {
-
-// Key comparison function for C strings.
-struct CStringLt {
- bool operator()(const char* s1, const char* s2) const {
- return strcmp(s1, s2) < 0;
- }
-};
-
-// Key equality function for C strings.
-struct CStringEq {
- bool operator()(const char* s1, const char* s2) const {
- return strcmp(s1, s2) == 0;
- }
-};
-
-} // namespace art
-
-#endif // ART_RUNTIME_STRUTIL_H_
#include "barrier.h"
#include "base/mutex.h"
-#include "closure.h"
#include "mem_map.h"
namespace art {
class ThreadPool;
+class Closure {
+ public:
+ virtual ~Closure() { }
+ virtual void Run(Thread* self) = 0;
+};
+
class Task : public Closure {
public:
// Called when references reaches 0.