RUNTIME_ARRAY usage

This commit is contained in:
Alexey Pelykh 2013-02-04 20:02:46 +02:00
parent edbea8ac2b
commit e6fc4e3bea
5 changed files with 23 additions and 39 deletions

View File

@ -2555,7 +2555,7 @@ class MyAssembler: public Assembler {
OperandType type; OperandType type;
Operand* operand; Operand* operand;
}; };
Argument* arguments = new Argument[argumentCount]; RUNTIME_ARRAY(Argument, arguments, argumentCount);
va_list a; va_start(a, argumentCount); va_list a; va_start(a, argumentCount);
unsigned footprint = 0; unsigned footprint = 0;
@ -2590,9 +2590,6 @@ class MyAssembler: public Assembler {
offset += ceiling(arguments[i].size, TargetBytesPerWord); offset += ceiling(arguments[i].size, TargetBytesPerWord);
} }
} }
delete[] arguments;
arguments = 0;
} }
virtual void allocateFrame(unsigned footprint) { virtual void allocateFrame(unsigned footprint) {

View File

@ -182,7 +182,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes,
unsigned vfpIndex = 0; unsigned vfpIndex = 0;
unsigned vfpBackfillIndex UNUSED = 0; unsigned vfpBackfillIndex UNUSED = 0;
uintptr_t* stack = new uintptr_t[(argumentCount * 8) / BytesPerWord]; // is > argumentSize to account for padding RUNTIME_ARRAY(uintptr_t, stack, (argumentCount * 8) / BytesPerWord); // is > argumentSize to account for padding
unsigned stackIndex = 0; unsigned stackIndex = 0;
unsigned ai = 0; unsigned ai = 0;
@ -272,12 +272,10 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes,
} }
unsigned stackSize = stackIndex*BytesPerWord + ((stackIndex & 1) << 2); unsigned stackSize = stackIndex*BytesPerWord + ((stackIndex & 1) << 2);
auto retVal = vmNativeCall return vmNativeCall
(function, stackSize, stack, stackIndex * BytesPerWord, (function, stackSize, stack, stackIndex * BytesPerWord,
(gprIndex ? gprTable : 0), (gprIndex ? gprTable : 0),
(vfpIndex ? vfpTable : 0), returnType); (vfpIndex ? vfpTable : 0), returnType);
delete[] stack;
return retVal;
} }
} // namespace vm } // namespace vm

View File

@ -342,7 +342,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
unsigned count = s.read2() - 1; unsigned count = s.read2() - 1;
if (count) { if (count) {
Type* types = new Type[count + 2]; RUNTIME_ARRAY(Type, types, count + 2);
types[0] = Type_object; types[0] = Type_object;
types[1] = Type_intptr_t; types[1] = Type_intptr_t;
@ -410,9 +410,6 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
(t, typeMaps, hashMapFind (t, typeMaps, hashMapFind
(t, root(t, Machine::PoolMap), c, objectHash, objectEqual), array, (t, root(t, Machine::PoolMap), c, objectHash, objectEqual), array,
objectHash); objectHash);
delete[] types;
types = 0;
} }
} }
@ -423,7 +420,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
object fields = allFields(t, typeMaps, c, &count, &array); object fields = allFields(t, typeMaps, c, &count, &array);
PROTECT(t, fields); PROTECT(t, fields);
Field* memberFields = new Field[count + 1]; RUNTIME_ARRAY(Field, memberFields, count + 1);
unsigned memberIndex; unsigned memberIndex;
unsigned buildMemberOffset; unsigned buildMemberOffset;
@ -447,7 +444,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
++ memberIndex; ++ memberIndex;
} }
} else { } else {
init(new (memberFields) Field, Type_object, 0, BytesPerWord, 0, init(new (&memberFields[0]) Field, Type_object, 0, BytesPerWord, 0,
TargetBytesPerWord); TargetBytesPerWord);
memberIndex = 1; memberIndex = 1;
@ -457,15 +454,15 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
const unsigned StaticHeader = 3; const unsigned StaticHeader = 3;
Field* staticFields = new Field[count + StaticHeader]; RUNTIME_ARRAY(Field, staticFields, count + StaticHeader);
init(new (staticFields) Field, Type_object, 0, BytesPerWord, 0, init(new (&staticFields[0]) Field, Type_object, 0, BytesPerWord, 0,
TargetBytesPerWord); TargetBytesPerWord);
init(new (staticFields + 1) Field, Type_intptr_t, BytesPerWord, init(new (&staticFields[1]) Field, Type_intptr_t, BytesPerWord,
BytesPerWord, TargetBytesPerWord, TargetBytesPerWord); BytesPerWord, TargetBytesPerWord, TargetBytesPerWord);
init(new (staticFields + 2) Field, Type_object, BytesPerWord * 2, init(new (&staticFields[2]) Field, Type_object, BytesPerWord * 2,
BytesPerWord, TargetBytesPerWord * 2, TargetBytesPerWord); BytesPerWord, TargetBytesPerWord * 2, TargetBytesPerWord);
unsigned staticIndex = StaticHeader; unsigned staticIndex = StaticHeader;
@ -515,7 +512,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
buildStaticOffset = fieldOffset(t, field); buildStaticOffset = fieldOffset(t, field);
init(new (staticFields + staticIndex) Field, type, init(new (&staticFields[staticIndex]) Field, type,
buildStaticOffset, buildSize, targetStaticOffset, buildStaticOffset, buildSize, targetStaticOffset,
targetSize); targetSize);
@ -529,7 +526,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
buildMemberOffset = fieldOffset(t, field); buildMemberOffset = fieldOffset(t, field);
init(new (memberFields + memberIndex) Field, type, init(new (&memberFields[memberIndex]) Field, type,
buildMemberOffset, buildSize, targetMemberOffset, buildMemberOffset, buildSize, targetMemberOffset,
targetSize); targetSize);
@ -552,7 +549,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
ceiling(targetMemberOffset, TargetBytesPerWord), memberIndex); ceiling(targetMemberOffset, TargetBytesPerWord), memberIndex);
for (unsigned i = 0; i < memberIndex; ++i) { for (unsigned i = 0; i < memberIndex; ++i) {
Field* f = memberFields + i; Field* f = &memberFields[i];
expect(t, f->buildOffset expect(t, f->buildOffset
< map->buildFixedSizeInWords * BytesPerWord); < map->buildFixedSizeInWords * BytesPerWord);
@ -576,7 +573,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
TypeMap::SingletonKind); TypeMap::SingletonKind);
for (unsigned i = 0; i < staticIndex; ++i) { for (unsigned i = 0; i < staticIndex; ++i) {
Field* f = staticFields + i; Field* f = &staticFields[i];
expect(t, f->buildOffset expect(t, f->buildOffset
< map->buildFixedSizeInWords * BytesPerWord); < map->buildFixedSizeInWords * BytesPerWord);
@ -589,12 +586,6 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
hashMapInsert hashMapInsert
(t, typeMaps, classStaticTable(t, c), array, objectHash); (t, typeMaps, classStaticTable(t, c), array, objectHash);
} }
delete[] memberFields;
memberFields = 0;
delete[] staticFields;
staticFields = 0;
} }
} }
} }
@ -1343,9 +1334,9 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
} }
++ count; ++ count;
Field* fields = new Field[count]; RUNTIME_ARRAY(Field, fields, count);
init(new (fields) Field, Type_object, 0, BytesPerWord, 0, init(new (&fields[0]) Field, Type_object, 0, BytesPerWord, 0,
TargetBytesPerWord); TargetBytesPerWord);
unsigned buildOffset = BytesPerWord; unsigned buildOffset = BytesPerWord;
@ -1423,7 +1414,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
++ targetOffset; ++ targetOffset;
} }
init(new (fields + j) Field, type, buildOffset, buildSize, init(new (&fields[j]) Field, type, buildOffset, buildSize,
targetOffset, targetSize); targetOffset, targetSize);
buildOffset += buildSize; buildOffset += buildSize;
@ -1458,7 +1449,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
targetArrayElementSize, arrayElementType); targetArrayElementSize, arrayElementType);
for (unsigned j = 0; j < fixedFieldCount; ++j) { for (unsigned j = 0; j < fixedFieldCount; ++j) {
Field* f = fields + j; Field* f = &fields[j];
expect(t, f->buildOffset expect(t, f->buildOffset
< map->buildFixedSizeInWords * BytesPerWord); < map->buildFixedSizeInWords * BytesPerWord);
@ -1471,9 +1462,6 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
hashMapInsert hashMapInsert
(t, typeMaps, vm::type(t, static_cast<Machine::Type>(i)), array, (t, typeMaps, vm::type(t, static_cast<Machine::Type>(i)), array,
objectHash); objectHash);
delete[] fields;
fields = 0;
} }
constants = makeCodeImage constants = makeCodeImage

View File

@ -243,6 +243,10 @@ class RuntimeArray {
free(body); free(body);
} }
T& operator[] (const unsigned index) {
return body[index];
}
T* body; T* body;
}; };

View File

@ -2321,7 +2321,7 @@ interpret3(Thread* t, const int base)
object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1);
PROTECT(t, class_); PROTECT(t, class_);
int32_t* counts = new int32_t[dimensions]; RUNTIME_ARRAY(int32_t, counts, dimensions);
for (int i = dimensions - 1; i >= 0; --i) { for (int i = dimensions - 1; i >= 0; --i) {
counts[i] = popInt(t); counts[i] = popInt(t);
if (UNLIKELY(counts[i] < 0)) { if (UNLIKELY(counts[i] < 0)) {
@ -2338,9 +2338,6 @@ interpret3(Thread* t, const int base)
populateMultiArray(t, array, counts, 0, dimensions); populateMultiArray(t, array, counts, 0, dimensions);
pushObject(t, array); pushObject(t, array);
delete[] counts;
counts = 0;
} goto loop; } goto loop;
case new_: { case new_: {