The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / src / code-stubs.cc @ 40c0f755

History | View | Annotate | Download (4.43 KB)

1
// Copyright 2006-2008 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
//     * Redistributions of source code must retain the above copyright
7
//       notice, this list of conditions and the following disclaimer.
8
//     * Redistributions in binary form must reproduce the above
9
//       copyright notice, this list of conditions and the following
10
//       disclaimer in the documentation and/or other materials provided
11
//       with the distribution.
12
//     * Neither the name of Google Inc. nor the names of its
13
//       contributors may be used to endorse or promote products derived
14
//       from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27

    
28
#include "v8.h"
29

    
30
#include "bootstrapper.h"
31
#include "code-stubs.h"
32
#include "factory.h"
33
#include "macro-assembler.h"
34

    
35
namespace v8 { namespace internal {
36

    
37
Handle<Code> CodeStub::GetCode() {
38
  uint32_t key = GetKey();
39
  int index = Heap::code_stubs()->FindNumberEntry(key);
40
  if (index == -1) {
41
    HandleScope scope;
42

    
43
    // Update the static counter each time a new code stub is generated.
44
    Counters::code_stubs.Increment();
45

    
46
    // Generate the new code.
47
    MacroAssembler masm(NULL, 256);
48

    
49
    // Nested stubs are not allowed for leafs.
50
    masm.set_allow_stub_calls(AllowsStubCalls());
51

    
52
    // Generate the code for the stub.
53
    masm.set_generating_stub(true);
54
    Generate(&masm);
55

    
56
    // Create the code object.
57
    CodeDesc desc;
58
    masm.GetCode(&desc);
59

    
60
    // Copy the generated code into a heap object, and store the major key.
61
    Code::Flags flags = Code::ComputeFlags(Code::STUB);
62
    Handle<Code> code = Factory::NewCode(desc, NULL, flags, masm.CodeObject());
63
    code->set_major_key(MajorKey());
64

    
65
    // Add unresolved entries in the code to the fixup list.
66
    Bootstrapper::AddFixup(*code, &masm);
67

    
68
    LOG(CodeCreateEvent("Stub", *code, GetName()));
69
    Counters::total_stubs_code_size.Increment(code->instruction_size());
70

    
71
#ifdef ENABLE_DISASSEMBLER
72
    if (FLAG_print_code_stubs) {
73
#ifdef DEBUG
74
      Print();
75
#endif
76
      code->Disassemble(GetName());
77
      PrintF("\n");
78
    }
79
#endif
80

    
81
    // Update the dictionary and the root in Heap.
82
    Handle<Dictionary> dict =
83
        Factory::DictionaryAtNumberPut(Handle<Dictionary>(Heap::code_stubs()),
84
                                       key,
85
                                       code);
86
    Heap::set_code_stubs(*dict);
87
    index = Heap::code_stubs()->FindNumberEntry(key);
88
  }
89
  ASSERT(index != -1);
90

    
91
  return Handle<Code>(Code::cast(Heap::code_stubs()->ValueAt(index)));
92
}
93

    
94

    
95
const char* CodeStub::MajorName(CodeStub::Major major_key) {
96
  switch (major_key) {
97
    case CallFunction:
98
      return "CallFunction";
99
    case GenericBinaryOp:
100
      return "GenericBinaryOp";
101
    case SmiOp:
102
      return "SmiOp";
103
    case Compare:
104
      return "Compare";
105
    case RecordWrite:
106
      return "RecordWrite";
107
    case StackCheck:
108
      return "StackCheck";
109
    case UnarySub:
110
      return "UnarySub";
111
    case RevertToNumber:
112
      return "RevertToNumber";
113
    case ToBoolean:
114
      return "ToBoolean";
115
    case Instanceof:
116
      return "Instanceof";
117
    case CounterOp:
118
      return "CounterOp";
119
    case ArgumentsAccess:
120
      return "ArgumentsAccess";
121
    case Runtime:
122
      return "Runtime";
123
    case CEntry:
124
      return "CEntry";
125
    case JSEntry:
126
      return "JSEntry";
127
    case GetProperty:
128
      return "GetProperty";
129
    case SetProperty:
130
      return "SetProperty";
131
    case InvokeBuiltin:
132
      return "InvokeBuiltin";
133
    case JSExit:
134
      return "JSExit";
135
    default:
136
      UNREACHABLE();
137
      return NULL;
138
  }
139
}
140

    
141

    
142
} }  // namespace v8::internal