Skip to content

Commit 9a1acb3

Browse files
committed
Remove some unnecessary use of streams.
Remove some lingering uses of signed heap sizes.
1 parent 01798dd commit 9a1acb3

File tree

6 files changed

+19
-34
lines changed

6 files changed

+19
-34
lines changed

vm/heap.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ bool Heap::ScavengePointer(Object* ptr) {
551551
new_target = ForwardingTarget(old_target);
552552
} else {
553553
// Target is now known to be reachable. Move it to to-space.
554-
intptr_t size = old_target->HeapSize();
554+
size_t size = old_target->HeapSize();
555555

556556
uword new_target_addr;
557557
if (old_target->Addr() < survivor_end_) {
@@ -611,7 +611,7 @@ bool Heap::ScavengeClass(intptr_t cid) {
611611
}
612612

613613
// Target is now known to be reachable. Move it to to-space.
614-
intptr_t size = old_target->HeapSize();
614+
size_t size = old_target->HeapSize();
615615

616616
uword new_target_addr;
617617
if (old_target->Addr() < survivor_end_) {
@@ -810,7 +810,7 @@ bool Heap::SweepRegion(Region* region) {
810810
HeapObject obj = HeapObject::FromAddr(scan);
811811
if (obj->is_marked()) {
812812
obj->set_is_marked(false);
813-
intptr_t size = obj->HeapSize();
813+
size_t size = obj->HeapSize();
814814
old_size_ += size;
815815
scan += size;
816816
} else {

vm/os_android.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ void OS::Print(const char* format, ...) {
6767
va_list args;
6868

6969
va_start(args, format);
70-
vfprintf(stdout, format, args);
71-
fflush(stdout);
70+
vdprintf(STDOUT_FILENO, format, args);
7271
va_end(args);
7372

7473
va_start(args, format);
@@ -80,8 +79,7 @@ void OS::PrintErr(const char* format, ...) {
8079
va_list args;
8180

8281
va_start(args, format);
83-
vfprintf(stderr, format, args);
84-
fflush(stderr);
82+
vdprintf(STDERR_FILENO, format, args);
8583
va_end(args);
8684

8785
va_start(args, format);

vm/os_fuchsia.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,17 @@ intptr_t OS::NumberOfAvailableProcessors() {
4343
return zx_system_get_num_cpus();
4444
}
4545

46-
static void VFPrint(FILE* stream, const char* format, va_list args) {
47-
vfprintf(stream, format, args);
48-
fflush(stream);
49-
}
50-
5146
void OS::Print(const char* format, ...) {
5247
va_list args;
5348
va_start(args, format);
54-
VFPrint(stdout, format, args);
49+
vdprintf(STDOUT_FILENO, format, args);
5550
va_end(args);
5651
}
5752

5853
void OS::PrintErr(const char* format, ...) {
5954
va_list args;
6055
va_start(args, format);
61-
VFPrint(stderr, format, args);
56+
vdprintf(STDERR_FILENO, format, args);
6257
va_end(args);
6358
}
6459

vm/os_linux.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,17 @@ intptr_t OS::NumberOfAvailableProcessors() {
7070
return sysconf(_SC_NPROCESSORS_ONLN);
7171
}
7272

73-
static void VFPrint(FILE* stream, const char* format, va_list args) {
74-
vfprintf(stream, format, args);
75-
fflush(stream);
76-
}
77-
7873
void OS::Print(const char* format, ...) {
7974
va_list args;
8075
va_start(args, format);
81-
VFPrint(stdout, format, args);
76+
vdprintf(STDOUT_FILENO, format, args);
8277
va_end(args);
8378
}
8479

8580
void OS::PrintErr(const char* format, ...) {
8681
va_list args;
8782
va_start(args, format);
88-
VFPrint(stderr, format, args);
83+
vdprintf(STDERR_FILENO, format, args);
8984
va_end(args);
9085
}
9186

vm/os_macos.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,17 @@ intptr_t OS::NumberOfAvailableProcessors() {
4545
return sysconf(_SC_NPROCESSORS_ONLN);
4646
}
4747

48-
static void VFPrint(FILE* stream, const char* format, va_list args) {
49-
vfprintf(stream, format, args);
50-
fflush(stream);
51-
}
52-
5348
void OS::Print(const char* format, ...) {
5449
va_list args;
5550
va_start(args, format);
56-
VFPrint(stdout, format, args);
51+
vdprintf(STDOUT_FILENO, format, args);
5752
va_end(args);
5853
}
5954

6055
void OS::PrintErr(const char* format, ...) {
6156
va_list args;
6257
va_start(args, format);
63-
VFPrint(stderr, format, args);
58+
vdprintf(STDERR_FILENO, format, args);
6459
va_end(args);
6560
}
6661

vm/virtual_memory_posix.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
#include "vm/virtual_memory.h"
99

10+
#include <fcntl.h>
1011
#include <sys/mman.h>
1112
#include <sys/stat.h>
13+
#include <unistd.h>
1214

1315
#if defined(OS_ANDROID) || defined(OS_LINUX)
1416
#include <sys/prctl.h>
@@ -20,21 +22,21 @@
2022
namespace psoup {
2123

2224
MappedMemory MappedMemory::MapReadOnly(const char* filename) {
23-
FILE* file = fopen(filename, "r");
24-
if (file == nullptr) {
25+
int fd = open(filename, O_RDONLY | O_CLOEXEC);
26+
if (fd < 0) {
2527
FATAL("Failed to open '%s'\n", filename);
2628
}
2729
struct stat st;
28-
if (fstat(fileno(file), &st) != 0) {
30+
if (fstat(fd, &st) != 0) {
2931
FATAL("Failed to stat '%s'\n", filename);
3032
}
31-
intptr_t size = st.st_size;
33+
size_t size = st.st_size;
3234
void* address = mmap(nullptr, size, PROT_READ, MAP_FILE | MAP_PRIVATE,
33-
fileno(file), 0);
35+
fd, 0);
3436
if (address == MAP_FAILED) {
3537
FATAL("Failed to mmap '%s'\n", filename);
3638
}
37-
int result = fclose(file);
39+
int result = close(fd);
3840
ASSERT(result == 0);
3941

4042
return MappedMemory(address, size);

0 commit comments

Comments
 (0)