2013-10-16 08:10:36 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2013-10-16 08:10:36 +00:00
|
|
|
|
|
|
|
#ifndef V8_ALLOCATION_SITE_SCOPES_H_
|
|
|
|
#define V8_ALLOCATION_SITE_SCOPES_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/ast.h"
|
|
|
|
#include "src/handles.h"
|
|
|
|
#include "src/objects.h"
|
|
|
|
#include "src/zone.h"
|
2013-10-16 08:10:36 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
|
|
// AllocationSiteContext is the base class for walking and copying a nested
|
|
|
|
// boilerplate with AllocationSite and AllocationMemento support.
|
|
|
|
class AllocationSiteContext {
|
|
|
|
public:
|
2013-11-27 14:03:40 +00:00
|
|
|
explicit AllocationSiteContext(Isolate* isolate) {
|
2013-10-16 08:10:36 +00:00
|
|
|
isolate_ = isolate;
|
2014-05-09 12:59:24 +00:00
|
|
|
}
|
2013-10-16 08:10:36 +00:00
|
|
|
|
|
|
|
Handle<AllocationSite> top() { return top_; }
|
|
|
|
Handle<AllocationSite> current() { return current_; }
|
|
|
|
|
2013-11-27 14:03:40 +00:00
|
|
|
bool ShouldCreateMemento(Handle<JSObject> object) { return false; }
|
2013-10-16 08:10:36 +00:00
|
|
|
|
2013-11-25 12:41:27 +00:00
|
|
|
Isolate* isolate() { return isolate_; }
|
2013-10-16 08:10:36 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void update_current_site(AllocationSite* site) {
|
|
|
|
*(current_.location()) = site;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitializeTraversal(Handle<AllocationSite> site) {
|
|
|
|
top_ = site;
|
|
|
|
current_ = Handle<AllocationSite>(*top_, isolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
|
|
|
Handle<AllocationSite> top_;
|
|
|
|
Handle<AllocationSite> current_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// AllocationSiteCreationContext aids in the creation of AllocationSites to
|
|
|
|
// accompany object literals.
|
|
|
|
class AllocationSiteCreationContext : public AllocationSiteContext {
|
|
|
|
public:
|
|
|
|
explicit AllocationSiteCreationContext(Isolate* isolate)
|
2013-11-27 14:03:40 +00:00
|
|
|
: AllocationSiteContext(isolate) { }
|
2013-10-16 08:10:36 +00:00
|
|
|
|
2013-11-25 12:41:27 +00:00
|
|
|
Handle<AllocationSite> EnterNewScope();
|
|
|
|
void ExitScope(Handle<AllocationSite> site, Handle<JSObject> object);
|
2013-10-16 08:10:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// AllocationSiteUsageContext aids in the creation of AllocationMementos placed
|
|
|
|
// behind some/all components of a copied object literal.
|
|
|
|
class AllocationSiteUsageContext : public AllocationSiteContext {
|
|
|
|
public:
|
|
|
|
AllocationSiteUsageContext(Isolate* isolate, Handle<AllocationSite> site,
|
|
|
|
bool activated)
|
2013-11-27 14:03:40 +00:00
|
|
|
: AllocationSiteContext(isolate),
|
|
|
|
top_site_(site),
|
|
|
|
activated_(activated) { }
|
2013-10-16 08:10:36 +00:00
|
|
|
|
2013-11-25 12:41:27 +00:00
|
|
|
inline Handle<AllocationSite> EnterNewScope() {
|
|
|
|
if (top().is_null()) {
|
|
|
|
InitializeTraversal(top_site_);
|
|
|
|
} else {
|
|
|
|
// Advance current site
|
|
|
|
Object* nested_site = current()->nested_site();
|
|
|
|
// Something is wrong if we advance to the end of the list here.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(nested_site->IsAllocationSite());
|
2013-11-25 12:41:27 +00:00
|
|
|
update_current_site(AllocationSite::cast(nested_site));
|
|
|
|
}
|
|
|
|
return Handle<AllocationSite>(*current(), isolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void ExitScope(Handle<AllocationSite> scope_site,
|
|
|
|
Handle<JSObject> object) {
|
|
|
|
// This assert ensures that we are pointing at the right sub-object in a
|
|
|
|
// recursive walk of a nested literal.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(object.is_null() || *object == scope_site->transition_info());
|
2013-11-25 12:41:27 +00:00
|
|
|
}
|
2013-10-16 08:10:36 +00:00
|
|
|
|
2013-11-27 14:03:40 +00:00
|
|
|
bool ShouldCreateMemento(Handle<JSObject> object);
|
|
|
|
|
2013-10-16 08:10:36 +00:00
|
|
|
private:
|
|
|
|
Handle<AllocationSite> top_site_;
|
2013-11-27 14:03:40 +00:00
|
|
|
bool activated_;
|
2013-10-16 08:10:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_ALLOCATION_SITE_SCOPES_H_
|