Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: vm/object.h

Issue 9481019: Changes to get rid of dependency on openssl in the dart VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « vm/isolate.cc ('k') | vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 2605 matching lines...) Expand 10 before | Expand all | Expand 10 after
2616 private: 2616 private:
2617 void set_value(int64_t value) const; 2617 void set_value(int64_t value) const;
2618 2618
2619 HEAP_OBJECT_IMPLEMENTATION(Mint, Integer); 2619 HEAP_OBJECT_IMPLEMENTATION(Mint, Integer);
2620 friend class Class; 2620 friend class Class;
2621 }; 2621 };
2622 2622
2623 2623
2624 class Bigint : public Integer { 2624 class Bigint : public Integer {
2625 public: 2625 public:
2626 virtual bool IsZero() const; 2626 virtual bool IsZero() const { return raw_ptr()->signed_length_ == 0; }
2627 virtual bool IsNegative() const; 2627 virtual bool IsNegative() const { return raw_ptr()->signed_length_ < 0; }
2628 2628
2629 virtual bool Equals(const Instance& other) const; 2629 virtual bool Equals(const Instance& other) const;
2630 2630
2631 virtual double AsDoubleValue() const; 2631 virtual double AsDoubleValue() const;
2632 virtual int64_t AsInt64Value() const; 2632 virtual int64_t AsInt64Value() const;
2633 2633
2634 virtual int CompareWith(const Integer& other) const; 2634 virtual int CompareWith(const Integer& other) const;
2635 2635
2636 static intptr_t InstanceSize(const BIGNUM* bn) { 2636 static intptr_t InstanceSize(intptr_t length) {
2637 // Danger Will Robinson! Use of OpenSSL internals! 2637 ASSERT(length >= 0);
2638 return RoundedAllocationSize(sizeof(RawBigint) 2638 return RoundedAllocationSize(sizeof(RawBigint) + (length * sizeof(Chunk)));
2639 + sizeof(BN_ULONG) * bn->top);
2640 } 2639 }
2641 static intptr_t InstanceSize() { 2640 static intptr_t InstanceSize() { return 0; }
2642 ASSERT(sizeof(RawBigint) == OFFSET_OF(RawBigint, data_));
2643 return 0;
2644 }
2645
2646 static RawBigint* New(const BIGNUM* bn, Heap::Space space = Heap::kNew);
2647 2641
2648 static RawBigint* New(const String& str, Heap::Space space = Heap::kNew); 2642 static RawBigint* New(const String& str, Heap::Space space = Heap::kNew);
2649 static RawBigint* New(int64_t value, Heap::Space space = Heap::kNew); 2643 static RawBigint* New(int64_t value, Heap::Space space = Heap::kNew);
2650 2644
2651 private: 2645 private:
2652 void SetSign(bool is_negative) const; 2646 typedef uint32_t Chunk;
2647 typedef uint64_t DoubleChunk;
2648 static const int kChunkSize = sizeof(Chunk);
2649
2650 Chunk GetChunkAt(intptr_t i) const {
2651 return *ChunkAddr(i);
2652 }
2653
2654 void SetChunkAt(intptr_t i, Chunk newValue) const {
2655 *ChunkAddr(i) = newValue;
2656 }
2657
2658 intptr_t Length() const {
2659 intptr_t signed_length = raw_ptr()->signed_length_;
2660 return Utils::Abs(signed_length);
2661 }
2662
2663 // SetLength does not change the sign.
2664 void SetLength(intptr_t length) const {
2665 ASSERT(length >= 0);
2666 bool is_negative = IsNegative();
2667 raw_ptr()->signed_length_ = length;
2668 if (is_negative) ToggleSign();
2669 }
2670
2671 void SetSign(bool is_negative) const {
2672 if (is_negative != IsNegative()) {
2673 ToggleSign();
2674 }
2675 }
2653 2676
2654 void ToggleSign() const { 2677 void ToggleSign() const {
2655 BIGNUM* bn = MutableBNAddr(); 2678 raw_ptr()->signed_length_ = -raw_ptr()->signed_length_;
2656 // Danger Will Robinson! Use of OpenSSL internals!
2657 // FIXME(benl): can be changed to use BN_set_negative() on more
2658 // recent OpenSSL releases (> 1.0.0).
2659 SetSign(!bn->neg);
2660 } 2679 }
2661 2680
2662 BIGNUM* MutableBNAddr() const { 2681 Chunk* ChunkAddr(intptr_t index) const {
2663 // Fix up internals as we may have been moved. 2682 ASSERT(0 <= index);
2664 raw_ptr()->bn_.d = BNMemory(); 2683 ASSERT(index < Length());
2665 2684 uword digits_start = reinterpret_cast<uword>(raw_ptr()) + sizeof(RawBigint);
2666 return &raw_ptr()->bn_; 2685 return &(reinterpret_cast<Chunk*>(digits_start)[index]);
2667 }
2668 const BIGNUM* BNAddr() const { return MutableBNAddr(); }
2669 BN_ULONG* BNMemory() const {
2670 return &raw_ptr()->data_[0];
2671 } 2686 }
2672 2687
2673 int NumberOfBits() const { return BN_num_bits(BNAddr()); } 2688 static RawBigint* Allocate(intptr_t length, Heap::Space space = Heap::kNew);
2674 bool IsBitSet(intptr_t bit) const { return Bit(bit) == 1; }
2675 int Bit(intptr_t bit) const { return BN_is_bit_set(BNAddr(), bit); }
2676 2689
2677 HEAP_OBJECT_IMPLEMENTATION(Bigint, Integer); 2690 HEAP_OBJECT_IMPLEMENTATION(Bigint, Integer);
2678 friend class Class; 2691 friend class Class;
2679 friend class BigintOperations; 2692 friend class BigintOperations;
2680 }; 2693 };
2681 2694
2682 2695
2683 class Double : public Number { 2696 class Double : public Number {
2684 public: 2697 public:
2685 double value() const { 2698 double value() const {
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
3754 } 3767 }
3755 3768
3756 3769
3757 void Context::SetAt(intptr_t index, const Instance& value) const { 3770 void Context::SetAt(intptr_t index, const Instance& value) const {
3758 StorePointer(InstanceAddr(index), value.raw()); 3771 StorePointer(InstanceAddr(index), value.raw());
3759 } 3772 }
3760 3773
3761 } // namespace dart 3774 } // namespace dart
3762 3775
3763 #endif // VM_OBJECT_H_ 3776 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « vm/isolate.cc ('k') | vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698