Project

General

Profile

Bug #9681 ยป 20141106-ruby2_1-r48288+r48289.patch

r48288 + r48289 for Ruby 2.1 - ngoto (Naohisa Goto), 11/06/2014 08:13 AM

View differences:

compile.c (working copy)
583 583
/* definition of data structure for compiler */
584 584
/*********************************************/
585 585

  
586
/*
587
 * On 32-bit SPARC, GCC by default generates SPARC V7 code that may require
588
 * 8-byte word alignment. On the other hand, Oracle Solaris Studio seems to
589
 * generate SPARCV8PLUS code with unaligned memory accesss instructions.
590
 * That is why the STRICT_ALIGNMENT is defined only with GCC.
591
 */
592
#if defined(__sparc) && SIZEOF_VOIDP == 4 && defined(__GNUC__)
593
  #define STRICT_ALIGNMENT
594
#endif
595

  
596
#ifdef STRICT_ALIGNMENT
597
  #if defined(HAVE_TRUE_LONG_LONG) && SIZEOF_LONG_LONG > SIZEOF_VALUE
598
    #define ALIGNMENT_SIZE SIZEOF_LONG_LONG
599
  #else
600
    #define ALIGNMENT_SIZE SIZEOF_VALUE
601
  #endif
602
  #define PADDING_SIZE_MAX    ((size_t)((ALIGNMENT_SIZE) - 1))
603
  #define ALIGNMENT_SIZE_MASK PADDING_SIZE_MAX
604
  /* Note: ALIGNMENT_SIZE == (2 ** N) is expected. */
605
#else
606
  #define PADDING_SIZE_MAX 0
607
#endif /* STRICT_ALIGNMENT */
608

  
609
#ifdef STRICT_ALIGNMENT
610
/* calculate padding size for aligned memory access */
611
static size_t
612
calc_padding(void *ptr, size_t size)
613
{
614
    size_t mis;
615
    size_t padding = 0;
616

  
617
    mis = (size_t)ptr & ALIGNMENT_SIZE_MASK;
618
    if (mis > 0) {
619
        padding = ALIGNMENT_SIZE - mis;
620
    }
621
/*
622
 * On 32-bit sparc or equivalents, when a single VALUE is requested
623
 * and padding == sizeof(VALUE), it is clear that no padding is needed.
624
 */
625
#if ALIGNMENT_SIZE > SIZEOF_VALUE
626
    if (size == sizeof(VALUE) && padding == sizeof(VALUE)) {
627
        padding = 0;
628
    }
629
#endif
630

  
631
    return padding;
632
}
633
#endif /* STRICT_ALIGNMENT */
634

  
586 635
static void *
587 636
compile_data_alloc(rb_iseq_t *iseq, size_t size)
588 637
{
589 638
    void *ptr = 0;
590 639
    struct iseq_compile_data_storage *storage =
591 640
	iseq->compile_data->storage_current;
641
#ifdef STRICT_ALIGNMENT
642
    size_t padding = calc_padding((void *)&storage->buff[storage->pos], size);
643
#else
644
    const size_t padding = 0; /* expected to be optimized by compiler */
645
#endif /* STRICT_ALIGNMENT */
592 646

  
593
    if (storage->pos + size > storage->size) {
647
    if (storage->pos + size + padding > storage->size) {
594 648
	unsigned long alloc_size = storage->size * 2;
595 649

  
596 650
      retry:
597
	if (alloc_size < size) {
651
	if (alloc_size < size + PADDING_SIZE_MAX) {
598 652
	    alloc_size *= 2;
599 653
	    goto retry;
600 654
	}
......
606 660
	storage->pos = 0;
607 661
	storage->size = alloc_size;
608 662
	storage->buff = (char *)(&storage->buff + 1);
663
#ifdef STRICT_ALIGNMENT
664
        padding = calc_padding((void *)&storage->buff[storage->pos], size);
665
#endif /* STRICT_ALIGNMENT */
609 666
    }
610 667

  
668
#ifdef STRICT_ALIGNMENT
669
    storage->pos += (int)padding;
670
#endif /* STRICT_ALIGNMENT */
671

  
611 672
    ptr = (void *)&storage->buff[storage->pos];
612 673
    storage->pos += size;
613 674
    return ptr;