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

Side by Side Diff: src/serialize.h

Issue 1018263002: Serializer: clean up opcodes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | src/serialize.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_SERIALIZE_H_ 5 #ifndef V8_SERIALIZE_H_
6 #define V8_SERIALIZE_H_ 6 #define V8_SERIALIZE_H_
7 7
8 #include "src/hashmap.h" 8 #include "src/hashmap.h"
9 #include "src/heap-profiler.h" 9 #include "src/heap-profiler.h"
10 #include "src/isolate.h" 10 #include "src/isolate.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 public: 296 public:
297 static void Iterate(Isolate* isolate, ObjectVisitor* visitor); 297 static void Iterate(Isolate* isolate, ObjectVisitor* visitor);
298 298
299 static int nop() { return kNop; } 299 static int nop() { return kNop; }
300 300
301 // No reservation for large object space necessary. 301 // No reservation for large object space necessary.
302 static const int kNumberOfPreallocatedSpaces = LO_SPACE; 302 static const int kNumberOfPreallocatedSpaces = LO_SPACE;
303 static const int kNumberOfSpaces = LAST_SPACE + 1; 303 static const int kNumberOfSpaces = LAST_SPACE + 1;
304 304
305 protected: 305 protected:
306 // ---------- byte code range 0x00..0x7f ----------
307 // Byte codes in this range represent Where, HowToCode and WhereToPoint.
306 // Where the pointed-to object can be found: 308 // Where the pointed-to object can be found:
307 enum Where { 309 enum Where {
308 kNewObject = 0, // Object is next in snapshot. 310 // 0x00..0x05 Allocate new object, in specified space.
309 // 1-6 One per space. 311 kNewObject = 0,
310 // 0x7, 0x8 Unused. 312 // 0x06 Unused (including 0x26, 0x46, 0x66).
311 kRootArray = 0x9, // Object is found in root array. 313 // 0x07 Unused (including 0x27, 0x47, 0x67).
312 kPartialSnapshotCache = 0xa, // Object is in the cache. 314 // 0x08..0x0d Reference to previous object from space.
313 kExternalReference = 0xb, // Pointer to an external reference. 315 kBackref = 0x08,
314 kSkip = 0xc, // Skip n bytes. 316 // 0x0e Unused (including 0x2e, 0x4e, 0x6e).
315 kBuiltin = 0xd, // Builtin code object. 317 // 0x0f Unused (including 0x2f, 0x4f, 0x6f).
316 kAttachedReference = 0xe, // Object is described in an attached list. 318 // 0x10..0x15 Reference to previous object from space after skip.
317 // 0xf Used by misc. See below. 319 kBackrefWithSkip = 0x10,
318 kBackref = 0x10, // Object is described relative to end. 320 // 0x16 Unused (including 0x36, 0x56, 0x76).
319 // 0x11-0x16 One per space. 321 // 0x17 Unused (including 0x37, 0x57, 0x77).
320 // 0x17 Unused. 322 // 0x18 Root array item.
321 kBackrefWithSkip = 0x18, // Object is described relative to end. 323 kRootArray = 0x18,
322 // 0x19-0x1e One per space. 324 // 0x19 Object in the partial snapshot cache.
323 // 0x1f Unused. 325 kPartialSnapshotCache = 0x19,
324 // 0x20-0x3f Used by misc. See below. 326 // 0x1a External reference referenced by id.
325 kPointedToMask = 0x3f 327 kExternalReference = 0x1a,
328 // 0x1b Object provided in the attached list.
329 kAttachedReference = 0x1b,
330 // 0x1c Builtin code referenced by index.
331 kBuiltin = 0x1c
332 // 0x1d..0x1e Misc (including 0x3d..0x3f, 0x5d..0x5f, 0x7d..0x7f)
333 // 0x1f Unused (including 0x3f, 0x5f, 0x7f).
326 }; 334 };
327 335
336 static const int kWhereMask = 0x1f;
337 static const int kSpaceMask = 7;
338 STATIC_ASSERT(kNumberOfSpaces <= kSpaceMask + 1);
339
328 // How to code the pointer to the object. 340 // How to code the pointer to the object.
329 enum HowToCode { 341 enum HowToCode {
330 kPlain = 0, // Straight pointer. 342 // Straight pointer.
331 // What this means depends on the architecture: 343 kPlain = 0,
332 kFromCode = 0x40, // A pointer inlined in code. 344 // A pointer inlined in code. What this means depends on the architecture.
333 kHowToCodeMask = 0x40 345 kFromCode = 0x20
334 }; 346 };
335 347
336 // For kRootArrayConstants 348 static const int kHowToCodeMask = 0x20;
337 enum WithSkip {
338 kNoSkipDistance = 0,
339 kHasSkipDistance = 0x40,
340 kWithSkipMask = 0x40
341 };
342 349
343 // Where to point within the object. 350 // Where to point within the object.
344 enum WhereToPoint { 351 enum WhereToPoint {
352 // Points to start of object
345 kStartOfObject = 0, 353 kStartOfObject = 0,
346 kInnerPointer = 0x80, // First insn in code object or payload of cell. 354 // Points to instruction in code object or payload of cell.
347 kWhereToPointMask = 0x80 355 kInnerPointer = 0x40
348 }; 356 };
349 357
350 // Misc. 358 static const int kWhereToPointMask = 0x40;
351 359
352 // 0x48, 0x88 and 0xc8 are unused. 360 // ---------- Misc ----------
353 361 // Skip.
354 // Raw data to be copied from the snapshot. This byte code does not advance 362 static const int kSkip = 0x1d;
355 // the current pointer, which is used for code objects, where we write the
356 // entire code in one memcpy, then fix up stuff with kSkip and other byte
357 // codes that overwrite data.
358 static const int kRawData = 0x20;
359 // Some common raw lengths: 0x21-0x3f.
360 // These autoadvance the current pointer.
361 static const int kOnePointerRawData = 0x21;
362
363 // Internal reference encoded as offsets of pc and target from code entry. 363 // Internal reference encoded as offsets of pc and target from code entry.
364 static const int kInternalReference = 0x08; 364 static const int kInternalReference = 0x1e;
365
366 static const int kVariableRepeat = 0x60;
367 // 0x61-0x6f Repeat last word
368 static const int kFixedRepeat = 0x61;
369 static const int kFixedRepeatBase = kFixedRepeat - 1;
370 static const int kLastFixedRepeat = 0x6f;
371 static const int kMaxFixedRepeats = kLastFixedRepeat - kFixedRepeatBase;
372 static int CodeForRepeats(int repeats) {
373 DCHECK(repeats >= 1 && repeats <= kMaxFixedRepeats);
374 return kFixedRepeatBase + repeats;
375 }
376 static int RepeatsForCode(int byte_code) {
377 DCHECK(byte_code > kFixedRepeatBase && byte_code <= kLastFixedRepeat);
378 return byte_code - kFixedRepeatBase;
379 }
380
381 // Hot objects are a small set of recently seen or back-referenced objects.
382 // They are represented by a single opcode to save space.
383 // We use 0x70..0x77 for 8 hot objects, and 0x78..0x7f to add skip.
384 static const int kHotObject = 0x70;
385 static const int kMaxHotObjectIndex = 0x77 - kHotObject;
386 static const int kHotObjectWithSkip = 0x78;
387 STATIC_ASSERT(HotObjectsList::kSize == kMaxHotObjectIndex + 1);
388 STATIC_ASSERT(0x7f - kHotObjectWithSkip == kMaxHotObjectIndex);
389 static const int kHotObjectIndexMask = 0x7;
390
391 static const int kRootArrayConstants = 0xa0;
392 // 0xa0-0xbf Things from the first 32 elements of the root array.
393 static const int kRootArrayNumberOfConstantEncodings = 0x20;
394 static int RootArrayConstantFromByteCode(int byte_code) {
395 return byte_code & 0x1f;
396 }
397
398 // Do nothing, used for padding. 365 // Do nothing, used for padding.
399 static const int kNop = 0xf; 366 static const int kNop = 0x3d;
400
401 // Move to next reserved chunk. 367 // Move to next reserved chunk.
402 static const int kNextChunk = 0x4f; 368 static const int kNextChunk = 0x3e;
403
404 // A tag emitted at strategic points in the snapshot to delineate sections. 369 // A tag emitted at strategic points in the snapshot to delineate sections.
405 // If the deserializer does not find these at the expected moments then it 370 // If the deserializer does not find these at the expected moments then it
406 // is an indication that the snapshot and the VM do not fit together. 371 // is an indication that the snapshot and the VM do not fit together.
407 // Examine the build process for architecture, version or configuration 372 // Examine the build process for architecture, version or configuration
408 // mismatches. 373 // mismatches.
409 static const int kSynchronize = 0x8f; 374 static const int kSynchronize = 0x5d;
410
411 // Used for the source code of the natives, which is in the executable, but 375 // Used for the source code of the natives, which is in the executable, but
412 // is referred to from external strings in the snapshot. 376 // is referred to from external strings in the snapshot.
413 static const int kNativesStringResource = 0xcf; 377 static const int kNativesStringResource = 0x5e;
378 // Raw data of variable length.
379 static const int kVariableRawData = 0x7d;
380 // Repeats of variable length.
381 static const int kVariableRepeat = 0x7e;
414 382
383 // ---------- byte code range 0x80..0xff ----------
384 // First 32 root array items.
385 static const int kNumberOfRootArrayConstants = 0x20;
386 // 0x80..0x9f
387 static const int kRootArrayConstants = 0x80;
388 // 0xa0..0xbf
389 static const int kRootArrayConstantsWithSkip = 0xa0;
390 static const int kRootArrayConstantsMask = 0x1f;
391
392 // 8 hot (recently seen or back-referenced) objects with optional skip.
393 static const int kNumberOfHotObjects = 0x08;
394 // 0xc0..0xc7
395 static const int kHotObject = 0xc0;
396 // 0xc8..0xcf
397 static const int kHotObjectWithSkip = 0xc8;
398 static const int kHotObjectMask = 0x07;
399
400 // 32 common raw data lengths.
401 static const int kNumberOfFixedRawData = 0x20;
402 // 0xd0..0xef
403 static const int kFixedRawData = 0xd0;
404 static const int kOnePointerRawData = kFixedRawData;
405 static const int kFixedRawDataStart = kFixedRawData - 1;
406
407 // 16 repeats lengths.
408 static const int kNumberOfFixedRepeat = 0x10;
409 // 0xf0..0xff
410 static const int kFixedRepeat = 0xf0;
411 static const int kFixedRepeatStart = kFixedRepeat - 1;
412
413 // ---------- special values ----------
415 static const int kAnyOldSpace = -1; 414 static const int kAnyOldSpace = -1;
416 415
417 // A bitmask for getting the space out of an instruction.
418 static const int kSpaceMask = 7;
419 STATIC_ASSERT(kNumberOfSpaces <= kSpaceMask + 1);
420
421 // Sentinel after a new object to indicate that double alignment is needed. 416 // Sentinel after a new object to indicate that double alignment is needed.
422 static const int kDoubleAlignmentSentinel = 0; 417 static const int kDoubleAlignmentSentinel = 0;
423 418
424 // Used as index for the attached reference representing the source object. 419 // Used as index for the attached reference representing the source object.
425 static const int kSourceObjectReference = 0; 420 static const int kSourceObjectReference = 0;
426 421
427 // Used as index for the attached reference representing the global proxy. 422 // Used as index for the attached reference representing the global proxy.
428 static const int kGlobalProxyReference = 0; 423 static const int kGlobalProxyReference = 0;
429 424
425 // ---------- member variable ----------
430 HotObjectsList hot_objects_; 426 HotObjectsList hot_objects_;
431 }; 427 };
432 428
433 429
434 class SerializedData { 430 class SerializedData {
435 public: 431 public:
436 class Reservation { 432 class Reservation {
437 public: 433 public:
438 explicit Reservation(uint32_t size) 434 explicit Reservation(uint32_t size)
439 : reservation_(ChunkSizeBits::encode(size)) {} 435 : reservation_(ChunkSizeBits::encode(size)) {}
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 kNumInternalizedStringsOffset + kInt32Size; 971 kNumInternalizedStringsOffset + kInt32Size;
976 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size; 972 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size;
977 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size; 973 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size;
978 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size; 974 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size;
979 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size; 975 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size;
980 static const int kHeaderSize = kChecksum2Offset + kInt32Size; 976 static const int kHeaderSize = kChecksum2Offset + kInt32Size;
981 }; 977 };
982 } } // namespace v8::internal 978 } } // namespace v8::internal
983 979
984 #endif // V8_SERIALIZE_H_ 980 #endif // V8_SERIALIZE_H_
OLDNEW
« no previous file with comments | « no previous file | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698